Features
Libraries
A code block with a language picker, a CodeMirror pane while editing and a highlighted card when read.
Installation#
bash
pnpm dlx shadcn@latest add @zui/document-editor @zui/editor-code-blockUsage#
tsx
import type { DocJSON, IEditor } from '@zeroxsolutions/editor-core/document/core/index';
import { codeBlock } from '@/components/editor/document/features/code-block';
import { standardKit } from '@/components/editor/document/features/standard';
import { Editor } from '@/components/editor/document/react';tsx
const features = [standardKit(), codeBlock()];
function NotesEditor({ content }: { content: DocJSON }) {
return <Editor features={features} content={content} />;
}codeBlock adds the codeBlock block, whose language and code attributes the editing pane and the highlighted card both read. Its slash item is "Code block" and its command insertCodeBlock takes an optional language and code.
Run the command on the editor that Editor hands to onReady, as Document Editor shows:
tsx
function insert(editor: IEditor) {
editor.run('insertCodeBlock', { language: 'typescript', code: 'const stops = 3;' });
}The Viewer draws the same block, with the same feature in its features, wherever a stored document is only read.