jbt / markdown-editor

Live (Github-flavored) Markdown Editor
http://jbt.github.com/markdown-editor
ISC License
2.83k stars 644 forks source link

Consider using CodeMirror.runmode for highlighting? #37

Closed vincentwoo closed 9 years ago

vincentwoo commented 9 years ago

If you're interested in cutting another dependency, you can use something like:

function highlight(code, lang) {
    var dummy = document.createElement('div');
    CodeMirror.runMode(code, lang, dummy);
    return dummy.innerHTML;
}

to perform highlighting instead of hljs. You do have to include all the relevant modes, though.

This has the added benefit of making sure the preview highlighting is identical to the output highlighting.

jbt commented 9 years ago

This is definitely something I've considered - having consistent highlighting on both input and output is something I'd very much like to have.

As it happens, though, the way I'm currently thinking of tackling that is to go in completely the opposite direction (sorry) and strip out CodeMirror entirely, and using prism for highlighting in both input and output. Current status is over on #25. Still definitely not final though

vincentwoo commented 9 years ago

I eagerly await your progress - I'm independently building out some of these features in CM land, and it's going... passably.