Last active
April 8, 2024 13:54
-
-
Save natterstefan/3bc712eca6ff88781d687b7240a78cc1 to your computer and use it in GitHub Desktop.
Revisions
-
natterstefan revised this gist
Sep 26, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,4 @@  This is the related [issue](https://github.com/remarkablemark/html-react-parser/issues/221#issuecomment-825601871) and [the solution](https://github.com/remarkablemark/html-react-parser/pull/296) that is by the time you read this probably merged already. -
natterstefan revised this gist
May 27, 2021 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,13 +5,9 @@ import React from 'react' import parse, { domToReact, attributesToProps, Element, HTMLReactParserOptions, } from 'html-react-parser' /** * I got some TS issues, that's why I came up with `typedDomNode`. -
natterstefan revised this gist
Apr 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,4 @@  Related to [this issue](https://github.com/remarkablemark/html-react-parser/issues/221#issuecomment-825601871). -
natterstefan revised this gist
Apr 29, 2021 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ # html-react-parser | TypeScript Error - instanceof Element always return false with Next.js  Related to [this issue](https://github.com/remarkablemark/html-react-parser/issues/221#issuecomment-825601871) -
natterstefan created this gist
Apr 23, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ /** * Works in Next.js 10.x */ import React from 'react' import parse, { domToReact, attributesToProps, HTMLReactParserOptions, } from 'html-react-parser' /** * only installed because of this issue, although it comes with html-react-parser already. * @see https://github.com/remarkablemark/html-react-parser/pull/201#issuecomment-825549767 */ import { Element } from 'domhandler/lib/node' /** * I got some TS issues, that's why I came up with `typedDomNode`. * * Related issues: * @see https://github.com/remarkablemark/html-react-parser/issues/221#issuecomment-771600574 */ const options: HTMLReactParserOptions = { replace: domNode => { const typedDomNode = domNode as Element if (typedDomNode.attribs && typedDomNode.name === 'a') { return ( <a {...attributesToProps(typedDomNode.attribs)} className="underline text-primary-500" target="_blank" > {typedDomNode.children && domToReact(typedDomNode.children, options)} </a> ) } return false }, } export const HTMLToReact = ({ html }: { html: string }) => { return <>{parse(html, options)}</> }