disable @ to insert links in code blocks

This commit is contained in:
chloelee767 2026-01-14 00:19:16 +08:00
parent e070fc2f52
commit c9ea0f9f7f
2 changed files with 25 additions and 0 deletions

View File

@ -31,6 +31,7 @@ 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";
import DisableMentionInCodeBlock from "./plugins/disable_mention_in_codeblock.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.
@ -53,6 +54,7 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [
MoveBlockUpDownPlugin,
ScrollOnUndoRedoPlugin,
InlineCodeNoSpellcheck,
DisableMentionInCodeBlock,
];
/**

View File

@ -0,0 +1,23 @@
import { Plugin } from "ckeditor5";
/**
* Disables the mention feature (triggered by `@`) inside code blocks.
* This prevents the autocomplete popup from appearing when typing `@` within code blocks.
*/
export default class DisableMentionInCodeBlock extends Plugin {
public static get pluginName() {
return "DisableMentionInCodeBlock" as const;
}
init() {
const editor = this.editor;
const schema = editor.model.schema;
// Disallow mention attribute inside code blocks
schema.addAttributeCheck((context, attributeName) => {
if (attributeName === 'mention' && context.endsWith('codeBlock $text')) {
return false;
}
});
}
}