Replace PrismJS/HyperMD syntax highlighting in favour of a maintained library

Use case or problem

(Unsure what system is actually been used now, seeing references to PrismJS on the forum in the past, but current markup leads me to HyperMD.)

PrismJS has not been maintained for the past 2–3 years. The main two maintainers have moved on to other projects and the development, if there ever was any, of PrismJS v2 is for all intents and purposes dead atfer 2 years of silence on the various issues.

HyperMD has similar issues.

In the mean time, popular programming languages like Python, Rust, and Go have added new language features which are not reflected in the syntax highlighting support for Obsidian because of this. A language like Zig is not even supported. I am sure there are other parts of the syntax highlighting that are also painfully behind in language support and fixes.

Example of the walrus operator (:=) from Python 3.8 (2019!) not being properly highlighted (the resulting HTML/CSS splits the := into two separate characters with semantic meaning underwater):

Proposed solution

Replace PrismJS/HyperMD with a maintained library. The better ones I have seen so far are:

They both also support the HTML 5 spec way of using code blocks with a <pre><code class="language-python"> kind of setup.

Current workaround (optional)

N/A

Related feature requests (optional)

N/A

Meanwhile there is shiki plugin. Pretty updated and you can add your own language and themes. Example here.

Hence, I will support shiki buit-in integration because of its features as capacity of importing “tmLanguage.json” file and VS Code theme.

+1    Adding syntax highlighting for Zig would be nice quality of life improvement. I’ve been dabbling with Zig for the last couple of weeks and my collection of Zig snippets is starting to grow.

Thank you all for the propal and reference! :pray:
That’s really needed!

Meanwhile, to have Zig snippets nicely coloured, I installed shiki.
It just shows a bigger font size than previously highlighter. I guess, for now, I should decrease that using CSS snippets.

I am using this CSS snippet to decrease it:

div.expressive-code {
  font-size: 15px !important;
}

Dusting this thread off with latest relevant concerns for Shiki afaik. Shiki Highlighter retains Obsidian’s CodeMirror 6 editor and applies Shiki-generated tokens through CM6 decorations with support across editing and Reading views. Relevant because it demonstrates that unified Shiki highlighting does not require replacing CodeMirror with Monaco, as previously assumed in an older related discussion.

Supporting would still require work in core, but it’s not as large a lift as replacing CodeMirror. A built-in Shiki backend or a syntax-highlighter API shared across all views are two options that would work I think.