From 83f602638bf96f5249e3b9856baf9f31b933fad1 Mon Sep 17 00:00:00 2001 From: yzhang <7588612+yzhang-gh@users.noreply.github.com> Date: Sun, 16 Jul 2023 20:45:44 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20#1310=20pure=20HTML?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 6 ++++++ package.nls.json | 1 + src/print.ts | 33 +++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 1d3e2067..e7c1b6a9 100644 --- a/package.json +++ b/package.json @@ -413,6 +413,12 @@ "description": "%config.print.onFileSave.description%", "scope": "resource" }, + "markdown.extension.print.pureHtml": { + "type": "boolean", + "default": false, + "description": "%config.print.pureHtml.description%", + "scope": "resource" + }, "markdown.extension.print.theme": { "type": "string", "default": "light", diff --git a/package.nls.json b/package.nls.json index e9847d57..5f7198ad 100644 --- a/package.nls.json +++ b/package.nls.json @@ -33,6 +33,7 @@ "config.print.imgToBase64.description": "Convert images to base64 when printing to HTML.", "config.print.includeVscodeStylesheets": "Include VS Code's basic Markdown styles so that the exported HTML looks similar as inside VS Code.", "config.print.onFileSave.description": "Print current document to HTML when file is saved.", + "config.print.pureHtml.description": "Print current document to pure HTML (without any stylesheets).", "config.print.theme": "Theme of the exported HTML. Only affects code blocks.", "config.print.validateUrls.description": "Enable/disable URL validation when printing.", "config.syntax.decorations.description": "(**Deprecated**) Use `#markdown.extension.theming.decoration.renderCodeSpan#` instead. See for details.", diff --git a/src/print.ts b/src/print.ts index b07fa9df..40403c04 100644 --- a/src/print.ts +++ b/src/print.ts @@ -145,22 +145,27 @@ async function print(type: string, uri?: Uri, outFolder?: string) { const extensionStyles = await getPreviewExtensionStyles(); const extensionScripts = await getPreviewExtensionScripts(); const includeVscodeStyles = config.get('print.includeVscodeStylesheets')!; + const pureHtml = config.get('print.pureHtml')!; const themeKind = config.get('print.theme'); const themeClass = themeKind === 'light' ? 'vscode-light' : themeKind === 'dark' ? 'vscode-dark' : ''; - const html = ` - - - - ${title ? encodeHTML(title) : ''} - ${extensionStyles} - ${getStyles(doc.uri, hasMath, includeVscodeStyles)} - - - ${body} - ${hasMath ? '' : ''} - ${extensionScripts} - - `; + + let html = body; + if (!pureHtml) { + html = ` + + + + ${title ? encodeHTML(title) : ''} + ${extensionStyles} + ${getStyles(doc.uri, hasMath, includeVscodeStyles)} + + + ${body} + ${hasMath ? '' : ''} + ${extensionScripts} + + `; + } switch (type) { case 'html':