Skip to content

Build your personal knowledge base with Trilium Notes

fix(markdown): slash commands can be triggered from code blocks

Elian Doranae0d77a646ce
diff --git a/apps/client/src/widgets/type_widgets/code/Markdown.tsx b/apps/client/src/widgets/type_widgets/code/Markdown.tsx
index f85c69653e..6b43c1e323 100644
--- a/apps/client/src/widgets/type_widgets/code/Markdown.tsx
+++ b/apps/client/src/widgets/type_widgets/code/Markdown.tsx
@@ -456,6 +456,11 @@ function useSlashCommands(parentComponent: TypeWidgetProps["parentComponent"], e
const match = ctx.matchBefore(/(?:^|(?<=\s))\/\w*/);
if (!match) return null;
+ // Suppress inside fenced code blocks (``` ... ```).
+ const textBefore = ctx.state.sliceDoc(0, match.from);
+ const fenceCount = (textBefore.match(/^(`{3,}|~{3,})/gm) ?? []).length;
+ if (fenceCount % 2 !== 0) return null;
+
return {
from: match.from,
options: [