Extended Code Highlight
approvedby Dong Yang
Additional and configurable syntax highlighting for code block languages. - This plugin has not been manually reviewed by Obsidian staff.
β¨ Extended Code Highlight
Extended Code Highlight adds broader, theme-compatible syntax highlighting for Obsidian code blocks in Reading view, Source mode, and Live Preview.
It supports all bundled PrismJS languages, bundled CodeMirror parser languages, and optional regex languages loaded from JSON files.
π Features
- Highlights more code block languages in both Reading view and editor views.
- Supports every PrismJS language id and alias bundled with the plugin.
- Uses CodeMirror parser highlighting where bundled parser support exists.
- Keeps highlighted code blocks editable in Live Preview.
- Reuses Obsidian's native
.token.*and.cm-*theme classes. - Lets you add custom regex-based languages as JSON files.
π Language Support
Use the normal language name after a fenced code block, such as js, ts, python, json, css, html, glsl, svelte, vue, zig, nix, or wasm.
The plugin supports:
- Every PrismJS language bundled from the PrismJS supported language list.
- Every CodeMirror parser language bundled in this plugin.
- Embedded regex fallback languages.
- User-defined regex languages that use the same JSON format.
You can check the upstream language lists here:
- PrismJS supported languages: prismjs.com/#supported-languages
- CodeMirror parser packages: codemirror.net/#language-support
Embedded fallback languages currently cover MLIR and Lean. Other bundled languages use PrismJS and/or CodeMirror support.
Highlighting priority depends on the Obsidian view:
- Reading view: PrismJS grammar first, then CodeMirror parser translated to Prism-style
.token.*spans, then regex fallback. - Source mode and Live Preview: CodeMirror parser first, then PrismJS token stream translated to Obsidian/CodeMirror
.cm-*classes, then regex fallback. - Regex JSON languages always use their token rules.
If a language is not built in, add a JSON file for it.
π§© Examples
```glsl
uniform sampler2D tex;
void main() {
vec4 color = texture2D(tex, vec2(0.5));
}
```
```svelte
<script lang="ts">
export let name = "world";
</script>
{#if name}
<h1>Hello {name}</h1>
{/if}
```
βοΈ Custom Languages
Create one JSON file per language in the plugin's languages folder:
<your-vault>/.obsidian/plugins/extended-code-highlight/languages/
Example:
{
"id": "mydsl",
"aliases": ["my-dsl"],
"tokens": [
{ "name": "comment", "pattern": ";.*", "flags": "m" },
{ "name": "keyword", "pattern": "\\b(foo|bar|baz)\\b" },
{ "name": "number", "pattern": "\\b\\d+(?:\\.\\d+)?\\b" },
{ "name": "string", "pattern": "\"(?:\\\\.|[^\"\\\\])*\"" }
]
}
Supported token names include comment, keyword, string, number, builtin, variable, function, property, and operator.
After editing a language JSON file, run the Reload extended highlight languages command or disable and re-enable the plugin.
π¨ Styling
The plugin uses Obsidian-compatible token classes so your current theme can style highlighted code.
Reading view uses Prism-style classes:
<span class="token keyword">...</span>
Editor views use CodeMirror-style classes:
cm-hmd-codeblock cm-keyword
π¦ Installation
Copy these files into your plugin folder:
<your-vault>/.obsidian/plugins/extended-code-highlight/
Required files:
manifest.json
main.js
Obsidian's community plugin installer only downloads main.js, manifest.json, and styles.css when present. Built-in language fallbacks are embedded into main.js; create custom JSON language files manually only if you need local additions.
Then enable Extended Code Highlight in Obsidian's Community plugins settings.
For plugin developers
Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.