I am new to rust and am trying to remove markdown comments from a (markdown) string. Are there any libraries to do this or any other suggestiongs that the community has?
What I have tried so far
regex replace - if there are multiple comments in the strings, it doesn't work as expected (rust regex does not support lookarounds)
explore any html/xml comment parsers. - wip, not optimistic that this will work out.
I don't think Markdown can be parsed by regular expressions. Most practical computer languages (markup or otherwise) can't, first and foremost because they allow nesting (i.e. recursion), which makes them non-regular.
Markdown is not HTML or XML, so you can't parse Markdown with an HTML or XML parser, either.
Also, to the best of my knowledge, Markdown has no concept of comments. Am I suspecting it right that you are actually trying to put HTML comments in Markdown and strip those? In that case, you will first need to parse the source with a Markdown parser that recognizes when it encounters some HTML. Then, you'll need to parse that inner HTML using an HTML parser to extract the comments.
I forget where I picked it up, but you can write a dummy footnote in a particular way, and it won't display in the rendered output (useful for mdbook).
That's right, I also found this technique searching on Stack Overflow for "markdown comment", and I found at least 3 different workarounds, but none of them seemed to be an intentional comments-in-markdown feature
This is quite difficult to do without parsing the string into markdown and then removing the comments. The best way is probably to use a markdown parser, otherwise it will take a lot more work and you will likely to have errors.