Skip to content

Commit

Permalink
#1310 pure HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhang-gh committed Jul 16, 2023
1 parent 99f85cf commit 83f6026
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/yzhang-gh/vscode-markdown/issues/888> for details.",
Expand Down
33 changes: 19 additions & 14 deletions src/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>('print.includeVscodeStylesheets')!;
const pureHtml = config.get<boolean>('print.pureHtml')!;
const themeKind = config.get<string>('print.theme');
const themeClass = themeKind === 'light' ? 'vscode-light' : themeKind === 'dark' ? 'vscode-dark' : '';
const html = `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>${title ? encodeHTML(title) : ''}</title>
${extensionStyles}
${getStyles(doc.uri, hasMath, includeVscodeStyles)}
</head>
<body class="vscode-body ${themeClass}">
${body}
${hasMath ? '<script async src="https://cdn.jsdelivr.net/npm/katex-copytex@latest/dist/katex-copytex.min.js"></script>' : ''}
${extensionScripts}
</body>
</html>`;

let html = body;
if (!pureHtml) {
html = `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>${title ? encodeHTML(title) : ''}</title>
${extensionStyles}
${getStyles(doc.uri, hasMath, includeVscodeStyles)}
</head>
<body class="vscode-body ${themeClass}">
${body}
${hasMath ? '<script async src="https://cdn.jsdelivr.net/npm/katex-copytex@latest/dist/katex-copytex.min.js"></script>' : ''}
${extensionScripts}
</body>
</html>`;
}

switch (type) {
case 'html':
Expand Down

0 comments on commit 83f6026

Please sign in to comment.