Skip to content

Build your personal knowledge base with Trilium Notes

feat(docs-edit): don't include HTML wrappers

Elian Doran460014e54f27
diff --git a/electron-docs-main.ts b/electron-docs-main.ts
index c0ec817834..724ee73b0c 100644
--- a/electron-docs-main.ts
+++ b/electron-docs-main.ts
@@ -99,6 +99,7 @@ async function exportData(noteId: string, format: "html" | "markdown", outputPat
const exportOpts: AdvancedExportOptions = {};
if (format === "html") {
+ exportOpts.skipHtmlTemplate = true;
exportOpts.customRewriteLinks = (originalRewriteLinks, getNoteTargetUrl) => {
return (content: string, noteMeta: NoteMeta) => {
content = content.replace(/src="[^"]*api\/images\/([a-zA-Z0-9_]+)\/[^"]*"/g, (match, targetNoteId) => {
diff --git a/src/services/export/zip.ts b/src/services/export/zip.ts
index 392b58cd29..5974d77eb9 100644
--- a/src/services/export/zip.ts
+++ b/src/services/export/zip.ts
@@ -26,6 +26,11 @@ import type { NoteMetaFile } from "../meta/note_meta.js";
type RewriteLinksFn = (content: string, noteMeta: NoteMeta) => string;
export interface AdvancedExportOptions {
+ /**
+ * If `true`, then only the note's content will be kept. If `false` (default), then each page will have its own <html> template.
+ */
+ skipHtmlTemplate?: boolean;
+
/**
* Provides a custom function to rewrite the links found in HTML or Markdown notes. This method is called for every note imported, if it's of the right type.
*
@@ -316,7 +321,7 @@ async function exportToZip(taskContext: TaskContext, branch: BBranch, format: "h
}
if (noteMeta.format === "html" && typeof content === "string") {
- if (!content.substr(0, 100).toLowerCase().includes("<html")) {
+ if (!content.substr(0, 100).toLowerCase().includes("<html") && !zipExportOptions?.skipHtmlTemplate) {
if (!noteMeta?.notePath?.length) {
throw new Error("Missing note path.");
}