[IPython-dev] markdown tangential discussion

Aron Ahmadia aron at ahmadia.net
Fri Aug 24 09:42:16 EDT 2012

> I hate to be a downer, but having implemented latex + wiki several times
> (ZWiki,
> jsMath+TiddlyWiki, etc), I can tell you that this solution is a hack that
> will
> fail eventually.  For that matter, it appears that Pagedown itself is a
> hack
> too, that will have bad edge cases.  (In other words it is a pile of
> successively applied regular expressions, in which one hopes there are not
> overlapping cases -- rather than a grammar which has no overlapping cases
> by
> definition)

The original MarkDown was implemented in Perl and was almost certainly a
pile of successively applied regular expressions.  I agree that we get much
nicer stuff with a proper parser, but somebody has to support it.  I don't
think I have anything against Markdown-js if the IPython developers decide
to switch to it (or somebody implements it in the notebook).

The correct solution to this problem is therefore to use a true grammar that
> involves an escape.  Since latex uses the backslash its escape character,
> and so
> does markdown, this seems naively easy, but one must hook into to
> markdown's
> processing stream, and call MathJax from it, rather than invoking two
> independent processing sessions (markdown followed by MathJax or v/v).

This isn't that hard.  The document's grammar is in Markdown or LaTeX
blocks.  The grammar becomes LaTeX whenever we enter a math-delimited
region.  Markdown is NOT allowed in a LaTeX region, and LaTeX is NOT
allowed in a Markdown region.  The important thing is to properly decompose
the text into Markdown-formatted text and LaTeX-formated text, and hide the
LaTeX from the Markdown processor (MathJaX confines itself to its delimited

The way SE does it (which I shamelessly copied), is to pull out all blocks
that are either delimited with classic TeX delimiters or contain anything
between $ $ that is not in a code block.  This effectively reserves all of
the major TeX environment delimiters within Markdown blocks ($$, \[,
\begin, etc., ...), which I think most people can live with.

> Markdown-js: https://github.com/evilstreak/markdown-js appears to be a
> much
> better written parser than Pagedown, in which inserting an extra rule for
> math,
> and calling MathJax would be straightforward (disabling MathJax's document
> parsing).

I don't see anything wrong with this approach.

> Correct me if I'm wrong, but this penchant for writing functions that
> generate
> classes that everyone is using basically makes it impossible to use
> inheritance
> to extend a Markdown parser.  (I don't understand why iPython,
> Markdown-js, and
> everyone in the known universe has decided this is The Way to write
> everything
> -- maybe someone can enlighten me)

functions and classes are first-class objects in Python and Javascript.
 You can modify a class or object's function after it has been instantiated
without inheriting.  I think this is a separate discussion, though.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20120824/7a2d194a/attachment.html>

More information about the IPython-dev mailing list