Skip to content

Build your personal knowledge base with Trilium Notes

text editor/collapsible: add a template in the markdown slash commands

Adorian Doran8b7be8a0a258
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 1d791992b7..7cad042c3d 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -265,6 +265,7 @@
"math": "Insert a math equation block",
"footnote": "Insert a footnote",
"mermaid": "Insert a Mermaid diagram",
+ "collapsible": "Insert a collapsible block",
"admonition": "Insert {{type}} admonition"
},
"move_to": {
diff --git a/apps/client/src/widgets/type_widgets/code/Markdown.spec.ts b/apps/client/src/widgets/type_widgets/code/Markdown.spec.ts
index af211f82fe..1c6ca302ea 100644
--- a/apps/client/src/widgets/type_widgets/code/Markdown.spec.ts
+++ b/apps/client/src/widgets/type_widgets/code/Markdown.spec.ts
@@ -84,6 +84,23 @@ describe("renderWithSourceLines", () => {
expect(html("Energy: $e=mc^2$.")).toContain('<span class="math-tex">');
});
+ it("renders the /collapsible template as a details block", () => {
+ // Mirrors the markdown the `/collapsible` slash command inserts.
+ const src = [
+ '<details class="trilium-collapsible">',
+ "<summary>Summary</summary>",
+ "",
+ "Details",
+ "",
+ "</details>"
+ ].join("\n");
+
+ const result = html(src);
+ expect(result).toContain("<details");
+ expect(result).toContain("<summary>Summary</summary>");
+ expect(result).toContain("Details");
+ });
+
it("renders [[wikilinks]] with hash-router hrefs so the preview navigates correctly", () => {
const result = html("See [[abc123]] for details.");
expect(result).toContain('class="reference-link"');
diff --git a/apps/client/src/widgets/type_widgets/code/Markdown.tsx b/apps/client/src/widgets/type_widgets/code/Markdown.tsx
index 70f734b689..3a4184386f 100644
--- a/apps/client/src/widgets/type_widgets/code/Markdown.tsx
+++ b/apps/client/src/widgets/type_widgets/code/Markdown.tsx
@@ -600,6 +600,22 @@ function useSlashCommands(parentComponent: TypeWidgetProps["parentComponent"], e
});
}
},
+ {
+ label: "/collapsible",
+ detail: t("markdown_slash_commands.collapsible"),
+ apply(view, _completion, from, to) {
+ // No native markdown syntax — round-trips through the
+ // importer as raw <details>/<summary> HTML (see markdown.ts).
+ const placeholder = "Summary";
+ const open = `<details class="trilium-collapsible">\n<summary>`;
+ const close = `</summary>\n\nDetails\n\n</details>`;
+ const anchor = from + open.length;
+ view.dispatch({
+ changes: { from, to, insert: open + placeholder + close },
+ selection: { anchor, head: anchor + placeholder.length }
+ });
+ }
+ },
...["note", "tip", "important", "caution", "warning"].map((admonitionType) => ({
label: `/${admonitionType}`,
detail: t("markdown_slash_commands.admonition", { type: admonitionType }),