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

Custom parser options #13

Open
ReyMagos opened this issue Apr 20, 2023 · 5 comments
Open

Custom parser options #13

ReyMagos opened this issue Apr 20, 2023 · 5 comments

Comments

@ReyMagos
Copy link

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
Copy link

What are you trying to parse here besides the usual?

@ReyMagos
Copy link
Author

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
Copy link
Owner

Hi, Currently the parser accepts only tokens that are parsed by marked. See

const tokens = props.isInline
? Lexer.lexInline(markdownString, lexerOptions)
: Lexer.lex(markdownString, lexerOptions);

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
Copy link

tanmayaBiswalOdiware commented Apr 24, 2023

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
Copy link
Owner

Currently I am working something with <Marked instance={customMarkedInstance} /> and planning to support extensions as well but it can be only done after markedjs/marked#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

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