Tobias Bengfort
2015-Apr-23 08:21 UTC
js syntax highlighting for markdown (not for codeblocks in markdown)
Hi, I am currently searching for a js library that will highlight markdown code. The trouble is that search engines only show me solutions for integrating markdown parsers with highlighting tools in order to highlight code blocks in the generated HTML. But that is not what I want. I want to write an in-browser markdown editor that has syntax highlighting for the markdown code itself. TL;DR: Does anyone know such a library? I have tried [highlight.js][1]. It has markdown support but unfortunately that is not really good. For example it can not find nested rules like this: > This is **bad**. And it does only look at single lines. So in the following example, all but the first line are interpreted as a code blocks. - My main point here is probably that blabla blablabla blablabla bla bla blabla bla blablabla bla blabla bla blablabla bla bla blabla bla blablabla bla. Thanks for your attention. It would be great if that library had optional features like fenced code blocks and intra-word emphasis. It would also be cool if it could spot errors (e.g. unbalanced emphasis like `**asd*`). Maybe it would be best if it was part of a markdown parser library because they could share some code and would have the same dialect (which is useful if you want syntax highlighting *and* a preview). I could probably write such a library myself, but I would prefer to use an existing one. For anyone interested in the editor idea: I know there are many markdown editors already. My favorite one is currently http://lab.lepture.com/editor/. My project is mainly for my personal entertainment and education. But I hope that the result will fill a gap. tobias [1]: https://highlightjs.org/
John MacFarlane
2015-Apr-23 14:57 UTC
js syntax highlighting for markdown (not for codeblocks in markdown)
You might find this interesting: http://talk.commonmark.org/t/experiment-highlighting-markdown-via-source-mapping/1132 I'm not sure if the project he's describing is js, though. CommonMark.NET already has complete source mapping. When I find time, I'll complete the source location information produced by commonmark.js (which currently gives you source location for block elements, but not inline elements). I don't think this would be too hard. https://github.com/jgm/commonmark.js/issues/28