Implementation:0xranx OpenContext HighlightJsExtension
| Knowledge Sources | |
|---|---|
| Domains | Editor, Syntax_Highlighting |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Tiptap extension that adds highlight.js-based syntax highlighting decorations to code block nodes via ProseMirror plugins.
Description
The HighlightJsExtension.js in src/ui/src/editor/tiptap/ is a Tiptap Extension that registers a ProseMirror plugin. On document changes, it traverses all codeBlock nodes, runs hljs.highlight (or hljs.highlightAuto for unknown languages) on the text content, and builds inline Decoration objects from the resulting HTML by walking the DOM tree and mapping CSS class names to inline decoration ranges. Language aliases (e.g., js→javascript) are normalized before highlighting.
Usage
Import and add this extension to the Tiptap editor's extensions array.
Code Reference
Source Location
- Repository: 0xranx_OpenContext
- File: src/ui/src/editor/tiptap/HighlightJsExtension.js
- Lines: 1-109
Signature
const HighlightJsExtension = Extension.create({
name: 'highlightjs',
addProseMirrorPlugins() { return [Plugin] }
});
export default HighlightJsExtension;
Import
import HighlightJsExtension from './editor/tiptap/HighlightJsExtension';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| codeBlock node | ProseMirror Node | Yes | Node with textContent and attrs.language |
Outputs
| Name | Type | Description |
|---|---|---|
| DecorationSet | ProseMirror | Inline decorations with hljs CSS classes |
Usage Examples
Adding to Tiptap Editor
import HighlightJsExtension from './editor/tiptap/HighlightJsExtension';
const editor = new Editor({
extensions: [
Document, Paragraph, Text,
CodeBlock.configure({ languageClassPrefix: 'language-' }),
HighlightJsExtension,
],
});