Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to parse custom components? #118

Open
denisidoro opened this issue Jul 23, 2020 · 3 comments
Open

How to parse custom components? #118

denisidoro opened this issue Jul 23, 2020 · 3 comments

Comments

@denisidoro
Copy link

denisidoro commented Jul 23, 2020

I expected this test to pass:

const ReactDOMServer = require('react-dom/server')
const HtmlToReactParser = require('html-to-react').Parser

const foo = () => "lorem"

const htmlInput = '<div><h1>Title</h1><foo/><p>A paragraph</p></div>'
const expected = '<div><h1>Title</h1>lorem<p>A paragraph</p></div>'

const htmlToReactParser = new HtmlToReactParser()
const reactElement = htmlToReactParser.parse(htmlInput)
const reactHtml = ReactDOMServer.renderToStaticMarkup(reactElement)

assert.notEqual(reactHtml, htmlInput)
assert.equal(reactHtml, expected)

However, reactHtml is equal to htmlInput in this case.

How to use custom options to achieve this without manually handling each node type?

@gkpo
Copy link

gkpo commented Dec 1, 2020

Same question here! I'd like to be able to parse Next.js Link components

@denisidoro
Copy link
Author

For reference, I ended up doing this: https://github.com/denisidoro/remacro/blob/master/core/src/renderer.js

@yadavravi2801
Copy link

Use Multiple Custom components

https://gist.github.com/yadavravi2801/001ac6a157b7018bf501f6fec41d8867

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants