rehypejs / rehype-raw

plugin to parse the tree again
https://unifiedjs.com
MIT License
142 stars 9 forks source link

Revert HAST to String #31

Closed gustavomm19 closed 9 months ago

gustavomm19 commented 9 months ago

Initial checklist

Problem

Is there a way to make the convertion optional for some components? I have a custom component in the Markdown Parser from react-markdown and I need it to keep its children always as a string, but if there is html content inside that content, that content gets parsed as nodes. Is there a way to prevent that? I need the plugin to make that convertion in other components but NOT in this one. Here is an example of my code

<ReactMarkdown
        remarkPlugins={[remarkGfm, remarkGemoji, remarkMath]}
        rehypePlugins={[rehypeRaw, rehypeKatex]}
        components={{
          codeviewer: CodeViewerComponent,
        }}
      >
        {preParsedContent}
      </ReactMarkdown>

Solution

Maybe if there were a function to unparse the children of a component

Alternatives

Or a list of components to just receive the children unparsed

JounQin commented 9 months ago

Welcome, @gustavomm19

Maybe you mean to use https://github.com/rehypejs/rehype/tree/main/packages/rehype-stringify

wooorm commented 9 months ago

I don’t think you’re working with html. HTML does not have that at all. It looks like you want jsx.

that’s not this project. You are likely looking for MDX

gustavomm19 commented 9 months ago

I solved this problem by using the position indexes of the node that comes as a prop, to extract the parts that I needed from the original content before it is parsed by the markdown parser

wooorm commented 9 months ago

I think you’re going in the wrong direction; there might be dragons, but good luck.

github-actions[bot] commented 9 months ago

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.