yogthos/markdown-clj

[RFE] Doc/demo/tutorial on syntax highlighting

clartaq opened this issue · 5 comments

It would be nice if you or someone else could provide some documentation or demonstration of how to do block-level syntax highlighting. For example, the clygments wrapper around the Pygments library seems a natural fit since Pygments could run on the JVM under Jython.

I'm assuming there would need to be a custom transformer to do this. I've looked at the code and see things that look relevant in the state map passed to such transformers, but do not understand how it should/would work. For example, it seems like Pygments might need to operate on an entire, multi-line expression, but the data is supplied to the transformer one line at a time. It's not clear how the lines should be accumulated and what should be output from the transformer as they are read.

Some guidance would be very helpful.

Typically, I tend to do syntax highlighting client-side using something like highlight.js, so I haven't really explored doing that in the parser. I suspect the best approach would be to simply generate the html first, and the run it through a highlighter as a second pass.

Hmmm... I had not considered that. I'll give it a try.

I'm probably using the library in a way you did not intend -- as a preview pane in a desktop markdown editor. So the markdown gets translated by your library and viewed on every keystroke. I use it for relatively small documentation files. Speed has not been an issue up to this point, but I'm not writing novel-length files either.

I've actually been very happy with the performance.

For small inputs performance shouldn't be too bad, but since the library evaluates the entire input each time, it definitely will slow down for larger inputs.

I would actually recommend taking a look at the Flexmark library for your use case. There's an example of using it from Clojure here.

Thanks for the pointer to Flexmark. It works fine too.

Consider my problem solved. You can close this if you want.

Glad to hear that works.