Extending lezer-markdown?

Hi there! With CM6 + lezer-markdown, I was hoping to be able to extend the commonmarkLanguage so that it could parse content enclosed in ${} as JavaScript, marking it as a special “TemplateSubstitution” node, or something like that, if you will. After looking into the markdown parser a bit more, I see that MarkdownExtensions can provide parseInline and/or parseBlock. This theoretical “TemplateSubstitution” would itself be inline (as it could start anywhere in a paragraph), but it also could include multiple newlines within it, which I wouldn’t want to be considered separate markdown blocks. Is it possible to do something like this with the markdown parser such that it ignores new lines until it finds this particular inline node’s closing (I see it’s possible to skipSpace but I think this is only within a given line…) or is this not really feasible with the markdown parser? Hope this question makes sense — thanks so much in advance for the help!!

No, that’s not currently possible—parsing happens in two phases: first the block structure is recognized, and then within that inline content is parsed. If your ${} escape contains, say, a blank line, that’ll end the enclosing paragraph. Of course, something like ${foo + \nbar} wouldn’t create empty lines or other markup that could end the paragraph, so that’d still work. But allowing any content in such a construct is hard to do with this parser.

1 Like