Skip to content

Build your personal knowledge base with Trilium Notes

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

lzinga52bb83e878bf
diff --git a/packages/ckeditor5/src/plugins.ts b/packages/ckeditor5/src/plugins.ts
index 81a8a7fe18..8f4e723f85 100644
--- a/packages/ckeditor5/src/plugins.ts
+++ b/packages/ckeditor5/src/plugins.ts
@@ -29,6 +29,7 @@ import CodeBlockToolbar from "./plugins/code_block_toolbar.js";
import CodeBlockLanguageDropdown from "./plugins/code_block_language_dropdown.js";
import MoveBlockUpDownPlugin from "./plugins/move_block_updown.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.
@@ -49,7 +50,8 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [
CodeBlockLanguageDropdown,
CodeBlockToolbar,
MoveBlockUpDownPlugin,
- ScrollOnUndoRedoPlugin
+ ScrollOnUndoRedoPlugin,
+ InlineCodeNoSpellcheck,
];
/**
diff --git a/packages/ckeditor5/src/plugins/inline_code_no_spellcheck.ts b/packages/ckeditor5/src/plugins/inline_code_no_spellcheck.ts
new file mode 100644
index 0000000000..2411691e4c
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/inline_code_no_spellcheck.ts
@@ -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'
+ });
+ }
+
+}