Markdown doesn't always generate XHTML

Petite Abeille petite.abeille at
Fri Mar 14 16:57:30 EDT 2008

On Mar 14, 2008, at 9:38 PM, Waylan Limberg wrote:

> I know that

> Python-Markdown has an option to not allow any html in a document

> (this "safe_mode" can be set to either replace with a customizable

> message, remove completely, or escape the html). Of course, to stay in

> line with the Markdown standard, it is off by default, but very easy

> to turn on in your code. Other implementations may offer a similar

> option.

Or one could preprocess the text directly before rendering it, e.g.:

aText = aText:gsub( '(`?)(<.->)(`?)', '`%2`' )
aText = markdown( aText )
aText = aText:gsub( '(`)(&lt;.-&gt;)(`)', '%2' )

That way anything between angle brackets is escaped.

Or at least this is what Nanoki, a wiki engine implemented in Lua,
does to protect the innocent from shooting themselves in the foot :)

Try to edit the online demo:

In theory, functional anomalies aside, Nanoki's pages should always
render as valid XHTML.


More information about the Markdown-Discuss mailing list