Experiment: Highlighting Markdown via source-mapping


#1

Hey guys, we’re currently playing with advanced source-mapping on a new parser, and did a little experiment.

Edit: changed link, added tooltip to show tree path on hover.
http://jmendeth.com/random/2015-04-09-hoedown-highlight/spec.md.html

This is what the CommonMark spec looks like, when highlighted with a CommonMark parser. Feel free to inspect away and change the styles, you can achieve crazy effects…

Feedback is welcome! I know highlighting isn’t what Markdown parsers were made for, but I’d say it’s still a pretty good fit, no?


#2

CommonMark.NET also has the ability and it is used by editors to do syntax highlighting (since the other more common option is to use simple regular expressions that sort-of work). Here is the worst case I know for markdown source mapping (and decided not to handle for now):

>>*foo
 >  >bar*

#3

Oooh! Thanks, I was having trouble finding CommonMark parsers with that feature.

What’s special about it? This is how it maps here:
http://s.codepen.io/jmendeth/debug/dPEPqg


#4

It’s special because the emphasis maps to two separate blocks (and the inner blockquote as well). In CommonMark.NET I track only a single block for each inline/block element (for memory and performance reasons) and thus it cannot represent the source mapping correctly for this case.


#5

This looks really good. I personally think the source-mapping is important. I hope you’re still working on it…


#6

Thanks! We’ll announce the parser in Implementation when we’re done.


#7

Do you have any news on this, @jmendeth?