I’m wondering what would be the recommended way to get both Markdown and Latex syntax highlighting working simultaneously, and I noticed there’s a function called parseMixed in the @lezer/common package to select a different parser for particular nodes. I would want for text surrounded by single (inline math mode) or double (display math mode) dollar-signs to be highlighted as Latex and everything outside as Markdown. Should I read the ranges from each node given by parseMixed and find matches with regex or should I extend the @lezer/markdown to add new node types for these sections? Also, would I have to modify the markdown table extension to allow for latex within tables?
Yes, write an extension for the markdown parser that recognizes dollar sign markup, and either directly integrate the math parsing in there, or use parseMixed to enable some kind of LaTeX parsing inside those nodes.
I copied the code for the Strikethough extension and made it work with dollar signs. Don’t know if I’m doing this correctly, but the mixed parsing wrapper became simply this:
Problem I’m running into now is that I would like to have a <div class="cm-math"> wrap the latex elements but I guess the parser replaces the “InlineMath” node with its own nodes. What’s the correct way of doing this?
I’m not sure how this block math markup works, but that code looks a bit dubious — you’re returning false when there’s only a single line prefixed with $$, and creating separate mabhBlockNode elements for every prefixed line beyond the first (but not for the first).
So, that ended up not working lol. What I wanna do is parse everything between the dollar signs (including the dollar signs themselves) as a MathBlock, regardless of where they are (I think this is how FencedCode is parsed). I guess doing this with parseBlock.parse won’t work since the start of a block doesn’t have to be at the beginning of a line. Anyway, the following examples should all be valid:
Hello there, I am also trying to do the same thing, I was wondering what parser are you using, are you using sTeX from the legacy parser?
I also managed to create a simple inline parser based off Strikethough extension, and I haven’t used the block parser so I may not be able help you unfortunately .
Edit: This post originally contained question about the usage of what I thought was an @internal constructor. I was was confused. The original question is below:
Details
This version of the parser does, however, use an @internal version of cx.elt(...):
I’m using this constructor to nest elements. Is there some other way I should be doing this?
Thanks a lot for sharing all those information. This allows us to activate mathematical expression highlighting in JupyterLab 4 (that switches to CodeMirror 6). For interested dev, you can have a look at: