sibiraj-s / marked-react

⚛️ Render Markdown as React components
https://sibiraj-s.github.io/marked-react/
MIT License
70 stars 11 forks source link

Custom parser options #13

Open ReyMagos opened 1 year ago

ReyMagos commented 1 year ago

Thank you for the great extension! It really helps!

So, I need to parse some custom markdown tokens from own tokenizer extension. I can add functions to custom renderer but is there an option to make parser recognize new token types?

tanmayaBiswalOdiware commented 1 year ago

What are you trying to parse here besides the usual?

ReyMagos commented 1 year ago

I have keyword that indicates following block should be wrapped into my component. And I need to handle this keyword in parser to properly set token type.

sibiraj-s commented 1 year ago

Hi, Currently the parser accepts only tokens that are parsed by marked. See https://github.com/sibiraj-s/marked-react/blob/6fbd187307fea86d0b65de58d4510627e4534bba/src/Markdown.ts#L39-L41

I'am open to suggestions to solve this, if marked allows to extend and parse into custom tokens, we could allow here as well. Why not.

tanmayaBiswalOdiware commented 1 year ago

I wondered for a while what you might be able to do here. Reading the marked documentation, you can see - we need to define a custom object as shown in the example. Maybe you can expose the lexar variable to the client in order to return a custom token. I am not completely sure how we go about doing that. Perhaps you can test it :)

sibiraj-s commented 1 year ago

Currently I am working something with <Marked instance={customMarkedInstance} /> and planning to support extensions as well but it can be only done after https://github.com/markedjs/marked/pull/2805, because the current @types/marked is messed up and doesn't exactly reflect marked library giving several errors with typescript.

Boy its not easy. I'll try but even if I support extensions, It might help your case, but it might not be possible to provide 100% support for extensions, as the renderer part in marked returns html and not react elements so it might be omitted