mdast-util-find-and-replace with HTML inside the Markdown
See original GitHub issueParsing MDX containing HTML
Hi,
Not sure this is a bug or a feature;
I’m trying to parse MDX which can contain some HTML. At the end i’m looking to use mdast-util-find-and-replace to replace some text terms in the markdown.
While trying to parse some markdown with mdast-util-from-markdown, i find a difference when the markdown starts with HTML tags
When parsing Some <b>HTML</b>content
the tree looks correct and the <b>
is a mdxJsxTextElement
. mdast-util-find-and-replace
can then operate on the text
element.
When parsing <p>Some HTML content</p>
, i only get a single html
element containing the <p>
tags, and in that case mdast-util-find-and-replace
is unable to replace the text
There is a full repro with failing test case here for illustration : https://codesandbox.io/s/addglossary-in-mdx-zxyzw?file=/src/index.js
Expected behavior
Even starting with html tags, the MDX should be fully parsed
Actual behavior
The markdown is parsed as a single html node
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (11 by maintainers)
Top GitHub Comments
Thanks for the explanation, it helps.
Our current use case is adding “tooltip” capabilities to various content, based on a glossary, so we just need to “wrap” these texts with some specific container. This will be used client-side to trigger the pretty tooltip.
HTML is a black box to markdown, with MDX, less so. But I thought I’d split the adding JSX vs removing HTML parts, it’s a bit confusing but at this level I thought it wise to split it!
Sounds interesting, what you’re doing with MDX at such a low level btw!