Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Add /page-break slash command to Markdown editor
Elian Dorane4588bff02ba
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 53147caaeb..f2ab53ef75 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -311,6 +311,7 @@"mermaid": "Insert a Mermaid diagram","mermaid_template": "Insert a \"{{name}}\" Mermaid diagram","collapsible": "Insert a collapsible block",+ "page_break": "Insert a page break (for printing)","admonition": "Insert {{type}} admonition","todo": "Insert a \"{{title}}\" task item","todo_nonstandard": "Insert a \"{{title}}\" task item (non-standard)",diff --git a/apps/client/src/widgets/type_widgets/code/Markdown.spec.ts b/apps/client/src/widgets/type_widgets/code/Markdown.spec.tsindex e146e5944c..c9e2f1d417 100644--- a/apps/client/src/widgets/type_widgets/code/Markdown.spec.ts+++ b/apps/client/src/widgets/type_widgets/code/Markdown.spec.ts@@ -122,6 +122,16 @@ describe("renderWithSourceLines", () => {expect(result).toContain("Details");});+ it("renders the /page-break template as a page-break div without swallowing following content", () => {+ // Mirrors the markdown the `/page-break` slash command inserts (note the trailing blank line).+ // The renderer must keep the `page-break` class through DOMPurify so print.css can drive the+ // page break, and the blank line must terminate the raw-HTML block so following text still+ // renders as markdown instead of being absorbed into the <div>.+ const result = html('<div class="page-break"></div>\n\nAfter the break');+ expect(result).toContain('class="page-break"');+ expect(result).toContain("<p>After the break</p>");+ });+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.tsxindex c47f85eed6..357bd9a614 100644--- a/apps/client/src/widgets/type_widgets/code/Markdown.tsx+++ b/apps/client/src/widgets/type_widgets/code/Markdown.tsx@@ -653,6 +653,21 @@ function useSlashCommands(parentComponent: TypeWidgetProps["parentComponent"], e});}},+ {+ label: "/page-break",+ detail: t("markdown_slash_commands.page_break"),+ apply(view, _completion, from, to) {+ // No native markdown syntax — round-trips through the+ // importer as raw HTML and drives the print/PDF page break (see print.css).+ // The trailing blank line terminates the raw-HTML block; without it the+ // text on the next line is swallowed into the <div> and never rendered.+ const insert = `<div class="page-break"></div>\n\n`;+ view.dispatch({+ changes: { from, to, insert },+ selection: { anchor: from + insert.length }+ });+ }+ },...["note", "tip", "important", "caution", "warning"].map((admonitionType) => ({label: `/${admonitionType}`,detail: t("markdown_slash_commands.admonition", { type: admonitionType }),