discussion add tag
Jack Douglas
***update***: we are now live with CodeMirror handling all syntax highlighting on TopAnswers.

---
…or, can we just use one syntax highlighting library instead of *three*!?

We have an APL community in beta, but [highlightjs](https://highlightjs.org) doesn't have an APL language mode — we could write one, but that might be hard, and I discovered that [prism](https://prismjs.com) has APL, so we lazily plugged that in instead.

But we are already using [CodeMirror](https://codemirror.net) for editing posts, and that has it's own syntax highlighting engine. You might not notice that it highlights everything differently if it was only used for highlighting the markdown for editing posts, but it is also used for:

1. [db<>fiddle](https://dbfiddle.uk/) code batches
2. the upcoming [TiO](https://tio.run) support for live code editing

So that's three. But we discovered recently that the CodeMirror library can be used just as a syntax highlighter in (roughly) the same way that highlightjs and prism are used. And we have figured out how to plug it in as the syntax highlighter for [markdown-it](https://github.com/markdown-it/markdown-it). And CodeMirror has an APL mode. Hmmmm.

We'd like to just use one library, and technically that is now possible, but we need to check that the syntax highlighting is up to scratch.

|Commuity|highlightjs|CodeMirror|
|--------|-----------|----------|
|databases.ta|![Screenshot 2020-05-06 at 12.45.28.png](/image?hash=4c60a7db51f949e6fc02f500bc691a66e938a187d9b5a15b66059f17c8fa5a70)|![Screenshot 2020-05-06 at 12.45.37.png](/image?hash=26a7aa742dadc1e3500992f8aa505208fe26eead261c672897fbe091510d27a9)|
|tex.ta|![Screenshot 2020-05-06 at 12.53.47.png](/image?hash=36327fad10397b9ca2f5cf8356e4cb37b45d9c1b5f7beb7713d5084031a4a907)|![Screenshot 2020-05-06 at 12.53.40.png](/image?hash=529d4313d1f1ed92cfe6e078e7da1e882d1ff9270ae81c43b1424023b1333121)|

**Is the CodeMirror highlighting good enough?**

The question isn't necessarily just about the colour theme as alternatives [are available](https://codemirror.net/demo/theme.html), but about the quality of the highlighting. Apparently CodeMirror uses a lexer rather than regex (used by highlightjs and prism), which [may be](https://stackoverflow.com/a/62930/12757754) an advantage[^1].

[^1]: Or as the [Prism docs](https://prismjs.com/#limitations) say:
"Regex-based so it \*will\* fail on certain edge cases"

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.