Dong Yang52 downloadsAdditional and configurable syntax highlighting for code block languages.
Additional and configurable syntax highlighting for Obsidian code blocks.
The plugin highlights code in both Reading view and editor/Live Preview mode. It ships with built-in language definitions for missing or inconsistent code block languages, and can be extended with regex-based token rules in languages.json.
languages.json.| Language | Fence names |
|---|---|
| WebAssembly text format | wasm, wat, wast, webassembly |
| Zig | zig |
| Nix | nix, nixos |
| HCL / Terraform | hcl, terraform, tf, tfvars |
| Kusto Query Language | kusto, kql |
| AutoHotkey | autohotkey, ahk |
| GDScript | gdscript, gd |
| MLIR | mlir |
| Lean | lean, lean4 |
| Angular templates | angular, ng |
| Vue single-file components | vue |
| Liquid templates | liquid, shopify |
| Less | less |
| Sass / SCSS | sass, scss |
| Svelte | svelte, sv |
Obsidian uses different highlighting paths across Reading view, Source mode, and Live Preview. This plugin keeps the supported language set consistent across those views by registering Prism-compatible rules and applying matching editor decorations.
```wat
(module
(func $add (param $a i32) (param $b i32) (result i32)
local.get $a
local.get $b
i32.add))
```
```svelte
<script lang="ts">
export let name = "world";
</script>
{#if name}
<h1>Hello {name}</h1>
{/if}
```
Create languages.json in the plugin directory. You can copy languages.example.json as a starting point.
{
"languages": [
{
"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": "\"(?:\\\\.|[^\"\\\\])*\"" }
]
}
]
}
Each language supports:
id: Primary fence name.aliases: Optional additional fence names.tokens: Ordered token rules.Each token supports:
name: CSS/token class, such as comment, keyword, string, number, builtin, variable, function, property, or operator.pattern: JavaScript regular expression source.flags: Optional regular expression flags.lookbehind / greedy: Optional Prism-compatible flags.After editing languages.json, run Reload extended highlight languages, use the plugin settings reload button, or disable and re-enable the plugin.
Obsidian uses PrismJS for Reading view code block highlighting, while Source mode and Live Preview use CodeMirror. Extended Code Highlight bridges those views with built-in language definitions and user-provided regex token definitions.
The current implementation is parser-first for built-in languages where parser support is available:
languages.json always use regex token rules in both Reading view and editor/Live Preview mode.Copy the built plugin files into:
<your-vault>/.obsidian/plugins/extended-code-highlight/
Required files:
manifest.json
main.js
styles.css
Then enable Extended Code Highlight from Obsidian's Community plugins settings.
Reading view tokens use Prism-style classes:
<span class="token keyword">...</span>
Editor tokens use CodeMirror decoration classes:
extended-code-highlight-editor-keyword
Customize colors in styles.css.
pnpm install
pnpm run build
Watch mode:
pnpm run dev
main.js is committed so the plugin can be installed directly without rebuilding.
Reload extended highlight languages after editing languages.json.registerMarkdownCodeBlockProcessor for normal highlighting.