feat(plugins): add InlineCodeNoSpellcheck plugin to disable spellcheck for inline code

This commit is contained in:
lzinga 2025-12-03 10:02:35 -08:00
parent 286a8626d1
commit 52bb83e878
2 changed files with 22 additions and 1 deletions

View File

@ -29,6 +29,7 @@ import CodeBlockToolbar from "./plugins/code_block_toolbar.js";
import CodeBlockLanguageDropdown from "./plugins/code_block_language_dropdown.js"; import CodeBlockLanguageDropdown from "./plugins/code_block_language_dropdown.js";
import MoveBlockUpDownPlugin from "./plugins/move_block_updown.js"; import MoveBlockUpDownPlugin from "./plugins/move_block_updown.js";
import ScrollOnUndoRedoPlugin from "./plugins/scroll_on_undo_redo.js" import ScrollOnUndoRedoPlugin from "./plugins/scroll_on_undo_redo.js"
import InlineCodeNoSpellcheck from "./plugins/inline_code_no_spellcheck.js";
/** /**
* Plugins that are specific to Trilium and not part of the CKEditor 5 core, included in both text editors but not in the attribute editor. * Plugins that are specific to Trilium and not part of the CKEditor 5 core, included in both text editors but not in the attribute editor.
@ -49,7 +50,8 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [
CodeBlockLanguageDropdown, CodeBlockLanguageDropdown,
CodeBlockToolbar, CodeBlockToolbar,
MoveBlockUpDownPlugin, MoveBlockUpDownPlugin,
ScrollOnUndoRedoPlugin ScrollOnUndoRedoPlugin,
InlineCodeNoSpellcheck,
]; ];
/** /**

View File

@ -0,0 +1,19 @@
import { Plugin } from "ckeditor5";
export default class InlineCodeNoSpellcheck extends Plugin {
init() {
const editor = this.editor;
editor.conversion.for('downcast').attributeToElement({
model: 'code',
view: (modelAttributeValue, conversionApi) => {
const { writer } = conversionApi;
return writer.createAttributeElement('code', {
spellcheck: 'false'
}, { priority: 5 });
},
converterPriority: 'high'
});
}
}