Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xranx OpenContext HighlightJsExtension

From Leeroopedia
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

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,
  ],
});

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment