[ANN] PEG Markdown Highlight

Bodhi bodhi at 5263.org
Wed Jun 29 04:13:58 EDT 2011



> the AST generated in phase 1 retains all positional information about the underlying markdown source



Hot damn! I asked about this about a year ago on this list when I was writing my Cocoa Markdown editor[1], but I couldn't get this info out of any of the C-based libraries easily. So my app ended up as a big hairy ball of regular expressions.

[1]: http://keshiki.net/markdown-editor (slightly outdated)
code: https://github.com/bodhi/markdownEditor

On 29/06/2011, at 6:03 PM, Mathias wrote:


> Related to this:

>

> For some time now there is a [markdown plugin][1] for the IntelliJ IDEA IDE and all derived ones (RubyMine, PhpStorm, etc). that does exactly what Ali is describing: syntax-highlighting based on the parser of an actual markdown processor, which in this case is [pegdown][2], that started off as a java port of John MacFarlane's peg-markdown.

>

> The way this works:

> pegdown does its markdown-to-HTML in two phases:

> 1. parsing of the markdown source into an Abstract Syntax Tree

> 2. serialization of the AST to HTML

>

> Since the AST generated in phase 1 retains all positional information about the underlying markdown source it's very easy to syntax-highlight the editor buffer based solely on this AST (which is exactly what the plugin is doing).

>

> So if anyone is looking for a markdown syntax-highlighting solution for the JVM pegdown is probably something to look at.

> For C-based applications the peg-markdown-highlight by Ali is certainly the better choice...

>

> Cheers,

> Mathias

>

> [1]: https://github.com/nicoulaj/idea-markdown

> [2]: http://www.pegdown.org

>

> ---

> mathias at parboiled.org

> http://www.parboiled.org

>

> On 28.06.2011, at 20:51, Ali Rantakari wrote:

>

>> Dear fellow Markdown enthusiasts,

>>

>> As you all might know, Markdown is a highly context sensitive language that the (often regex-based) syntax highlighting mechanisms in existing editors struggle to keep up with.

>>

>> I have taken John MacFarlane's excellent peg-markdown compiler and modified its parser to function as an interpreter for syntax highlighting purposes. The end result is a Markdown-specific syntax highlighter that should be able to match Markdown documents just as correctly as peg-markdown can, and that can easily be integrated into existing and new programs.

>>

>> You can find all the relevant information at the project web page:

>>

>> <http://hasseg.org/peg-markdown-highlight>

>>

>>

>> best,

>> - Ali Rantakari

>>

>>

>> _______________________________________________

>> Markdown-Discuss mailing list

>> Markdown-Discuss at six.pairlist.net

>> http://six.pairlist.net/mailman/listinfo/markdown-discuss

>

> _______________________________________________

> Markdown-Discuss mailing list

> Markdown-Discuss at six.pairlist.net

> http://six.pairlist.net/mailman/listinfo/markdown-discuss




More information about the Markdown-Discuss mailing list