mirror of
https://github.com/docmost/docmost.git
synced 2025-11-14 07:01:15 +10:00
46 lines
983 B
TypeScript
46 lines
983 B
TypeScript
import CodeBlockLowlight, {
|
|
CodeBlockLowlightOptions,
|
|
} from "@tiptap/extension-code-block-lowlight";
|
|
import { ReactNodeViewRenderer } from "@tiptap/react";
|
|
|
|
export interface CustomCodeBlockOptions extends CodeBlockLowlightOptions {
|
|
view: any;
|
|
}
|
|
|
|
const TAB_CHAR = "\u00A0\u00A0";
|
|
|
|
export const CustomCodeBlock = CodeBlockLowlight.extend<CustomCodeBlockOptions>(
|
|
{
|
|
selectable: true,
|
|
|
|
addOptions() {
|
|
return {
|
|
...this.parent?.(),
|
|
view: null,
|
|
};
|
|
},
|
|
|
|
addKeyboardShortcuts() {
|
|
return {
|
|
...this.parent?.(),
|
|
Tab: () => {
|
|
if (this.editor.isActive("codeBlock")) {
|
|
this.editor
|
|
.chain()
|
|
.command(({ tr }) => {
|
|
tr.insertText(TAB_CHAR);
|
|
return true;
|
|
})
|
|
.run();
|
|
return true;
|
|
}
|
|
},
|
|
};
|
|
},
|
|
|
|
addNodeView() {
|
|
return ReactNodeViewRenderer(this.options.view);
|
|
},
|
|
}
|
|
);
|