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

This commit is contained in:
Elian Doran
2025-04-12 00:27:15 +03:00
parent 9c0c1bad2d
commit 460014e54f
2 changed files with 7 additions and 1 deletions

View File

@@ -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) => {

View File

@@ -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.");
}