Markdown library that supports subset restriction?
For example, Stack Overflow allows only a very small subset of Markdown syntax i开发者_Go百科n comment editor.
I'd like to know if there is any open source Markdown library that supports syntax restriction? I'm currently using Python but I can't even find one in any language.
I've never used any Python Markdown parsers, but I have used a Java Markdown library called Pegdown that allows you to enable or disable various syntax extentions.
For example, this snippet enables Markdown Extra table syntax and disables both inline HTML and HTML blocks in the markdown input:
PegDownProcessor processor
= new PegDownProcessor(Parser.TABLES | Parser.SUPPRESS_ALL_HTML);
String html = processor.markdownToHtml(markdown);
Here is a list of all available PegDown extensions.
There is a C library called peg-markdown. The markdown syntax is defined as a grammar, so it is fairly easy to modify. To only allow a subset of markdown, you can remove the sections that match against the offending syntax so they won't be converted to tokens.
There are Ruby bindings for peg-markdown, but I suppose it should not be difficult to write bindings for Python.
精彩评论