feat(pdf): add configurable PDF export and improve print rendering

This commit is contained in:
Mateusz Gruszczyński
2026-09-12 00:01:25 +02:00
parent f9cf17554a
commit c5e01916c8
12 changed files with 584 additions and 14 deletions
+12 -1
View File
@@ -44,6 +44,16 @@ function toggleWrap(editor, before, after = before, placeholder = t("editor.form
if (!selected) editor.setSelectionRange(start + before.length, start + before.length + text.length);
}
export function insertPageBreak(editor) {
const { start, end } = selection(editor);
const value = editor.value;
const needsLeadingNewline = start > 0 && value[start - 1] !== "\n";
const needsTrailingNewline = end >= value.length || value[end] !== "\n";
const marker = `${needsLeadingNewline ? "\n" : ""}---${needsTrailingNewline ? "\n" : ""}`;
editor.setRangeText(marker, start, end, "end");
}
function togglePrefix(editor, prefixFactory) {
const { start, end } = selection(editor);
const lineStart = editor.value.lastIndexOf("\n", start - 1) + 1;
@@ -88,7 +98,7 @@ export function applyFormat(editor, format) {
if (format === "table") toggleWrap(editor, `| ${t("editor.format.column1", {}, "Column 1")} | ${t("editor.format.column2", {}, "Column 2")} |\n| --- | --- |\n| `, ` | ${t("editor.format.value", {}, "value")} |`, t("editor.format.value", {}, "value"));
if (format === "footnote") toggleWrap(editor, "", `[^1]\n\n[^1]: ${t("editor.format.footnote", {}, "Footnote text")}`, t("editor.format.textWithFootnote", {}, "Text with footnote"));
if (format === "definition") toggleWrap(editor, "", `\n: ${t("editor.format.definition", {}, "Definition")}`, t("editor.format.term", {}, "Term"));
if (format === "horizontal-rule") toggleWrap(editor, "\n---\n", "", "");
if (format === "page-break" || format === "horizontal-rule") insertPageBreak(editor);
editor.focus();
editor.dispatchEvent(new Event("input", { bubbles: true }));
}
@@ -104,6 +114,7 @@ export function bindFormatShortcuts(editor) {
else if (primary && !event.shiftKey && event.key.toLowerCase() === "k") format = "link";
else if (primary && event.shiftKey && event.key === "7") format = "number";
else if (primary && event.shiftKey && event.key === "8") format = "bullet";
else if (primary && !event.shiftKey && event.key === "Enter") format = "page-break";
else if (primary && event.shiftKey && event.key === "9") format = "task";
else if (event.altKey && /^[1-4]$/.test(event.key)) format = `heading${event.key}`;
if (!format) return;