How to add code block syntax highlighting language

Are there any guides on how I could add another language for syntax highlighting in code blocks?

I have searched far and wide for a plugin that allows syntax highlighting that combines language and diff, so for example C# with diff or TypeScript with diff. I want to try to implement something myself, but have no clue how to add custom syntax highlighting for code blocks, and the closest thing I found to helping (which didn’t) was the post below.

There are separate ways to syntax highlighting in edit mode and in preview mode

Edit mode (Source Mode / Live Preview)

Legacy CM5 way

window.CodeMirror.defineMode('new-language', (config) => {
  // ...
});

docs

Modern CM6 way

StreamLanguage.define()

Examples

Preview mode (Reading)

const prism = await loadPrism();
prism.languages['new-language'] = {
  // ...
};
2 Likes