Implementation:0xranx OpenContext Tiptap CodeBlockComponent
| Knowledge Sources | |
|---|---|
| Domains | Editor, React |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Tiptap NodeView component for code blocks with a language selector dropdown, language alias normalization, and highlight.js decorations.
Description
The CodeBlockComponent.jsx in src/ui/src/editor/tiptap/ is a React NodeView component for the Tiptap code block node. It renders a language dropdown with 27 language options and alias normalization (e.g., js→javascript, py→python). When the editor is editable and a raw language differs from its normalized form, it auto-updates the node attribute. The component uses NodeViewWrapper and NodeViewContent from @tiptap/react.
Usage
Import this component and register it as the NodeView for the code block extension in the Tiptap editor configuration.
Code Reference
Source Location
- Repository: 0xranx_OpenContext
- File: src/ui/src/editor/tiptap/CodeBlockComponent.jsx
- Lines: 1-176
Signature
function TiptapCodeBlockComponent({ node, updateAttributes, editor })
export default memo(TiptapCodeBlockComponent);
Import
import TiptapCodeBlockComponent from './editor/tiptap/CodeBlockComponent';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| node | object | Yes | Tiptap node with attrs.language |
| updateAttributes | Function | Yes | Tiptap attribute updater |
| editor | Editor | Yes | Tiptap editor instance |
Usage Examples
Registering with CodeBlock Extension
import CodeBlock from '@tiptap/extension-code-block';
import TiptapCodeBlockComponent from './editor/tiptap/CodeBlockComponent';
const CustomCodeBlock = CodeBlock.extend({
addNodeView() {
return ReactNodeViewRenderer(TiptapCodeBlockComponent);
}
});