Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markdown library that supports subset restriction?

Tags:

markdown

For example, Stack Overflow allows only a very small subset of Markdown syntax in 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.

like image 590
qingbo Avatar asked Aug 14 '11 15:08

qingbo


2 Answers

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.

like image 93
braveterry Avatar answered Oct 23 '22 12:10

braveterry


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.

like image 45
rekado Avatar answered Oct 23 '22 14:10

rekado