From 1b8124f2a201aa3af8fa62b3abf2dff4a693e4f0 Mon Sep 17 00:00:00 2001 From: "xiaoqi.cxq" Date: Sun, 26 Feb 2023 11:29:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BAHTML=E3=80=81PDF=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=B8=A6=E9=A2=84=E8=A7=88=E4=B8=BB=E9=A2=98=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + .../styledHtmlWithThemeAndTocTemplate.html | 33 +++++++++++++++++++ .../styledHtmlWithThemeTemplate.html | 26 +++++++++++++++ src/services/exportSvc.js | 8 +++++ src/store/data.js | 4 +++ 5 files changed, 72 insertions(+) create mode 100644 src/data/templates/styledHtmlWithThemeAndTocTemplate.html create mode 100644 src/data/templates/styledHtmlWithThemeTemplate.html diff --git a/README.md b/README.md index b6a1a9f1..d8bc5fe9 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ StackEdit中文版 - 支持MD文档之间链接跳转(2022-11-20) - 支持预览区域选择主题样式(2022-12-04) - Gitlab的支持优化(2023-02-23) +- 导出HTML、PDF支持带预览主题导出(2023-02-26) ## 国外开源版本弊端: - 作者已经不维护了 diff --git a/src/data/templates/styledHtmlWithThemeAndTocTemplate.html b/src/data/templates/styledHtmlWithThemeAndTocTemplate.html new file mode 100644 index 00000000..46fc205e --- /dev/null +++ b/src/data/templates/styledHtmlWithThemeAndTocTemplate.html @@ -0,0 +1,33 @@ + + + + + + + {{files.0.name}} + + + + +{{#if pdf}} + +{{else}} + +{{/if}} +
+
+ {{#tocToHtml files.0.content.toc 2}}{{/tocToHtml}} +
+
+
+
+
+ {{{files.0.content.html}}} +
+
+
+ + + diff --git a/src/data/templates/styledHtmlWithThemeTemplate.html b/src/data/templates/styledHtmlWithThemeTemplate.html new file mode 100644 index 00000000..00ecd7f4 --- /dev/null +++ b/src/data/templates/styledHtmlWithThemeTemplate.html @@ -0,0 +1,26 @@ + + + + + + + {{files.0.name}} + + + + +{{#if pdf}} + +{{else}} + +{{/if}} +
+
+ {{{files.0.content.html}}} +
+
+ + + diff --git a/src/services/exportSvc.js b/src/services/exportSvc.js index 373cc27b..8c553fae 100644 --- a/src/services/exportSvc.js +++ b/src/services/exportSvc.js @@ -73,6 +73,12 @@ export default { const parsingCtx = markdownConversionSvc.parseSections(converter, content.text); const conversionCtx = markdownConversionSvc.convert(parsingCtx); const html = conversionCtx.htmlSectionList.map(htmlSanitizer.sanitizeHtml).join(''); + const themeClass = `preview-theme--${store.state.theme.currPreviewTheme}`; + let themeStyleContent = ''; + const themeStyleEle = document.getElementById(`preview-theme-${store.state.theme.currPreviewTheme}`); + if (themeStyleEle) { + themeStyleContent = themeStyleEle.innerText; + } containerElt.innerHTML = html; extensionSvc.sectionPreview(containerElt, options); @@ -128,6 +134,8 @@ export default { yamlProperties: content.properties, html: containerElt.innerHTML, toc, + themeClass, + themeStyleContent, }, }], }; diff --git a/src/store/data.js b/src/store/data.js index 7c6ad5e0..fea30ebf 100644 --- a/src/store/data.js +++ b/src/store/data.js @@ -8,6 +8,8 @@ import defaultLayoutSettings from '../data/defaults/defaultLayoutSettings'; import plainHtmlTemplate from '../data/templates/plainHtmlTemplate.html'; import styledHtmlTemplate from '../data/templates/styledHtmlTemplate.html'; import styledHtmlWithTocTemplate from '../data/templates/styledHtmlWithTocTemplate.html'; +import styledHtmlWithThemeTemplate from '../data/templates/styledHtmlWithThemeTemplate.html'; +import styledHtmlWithThemeAndTocTemplate from '../data/templates/styledHtmlWithThemeAndTocTemplate.html'; import jekyllSiteTemplate from '../data/templates/jekyllSiteTemplate.html'; import constants from '../data/constants'; import features from '../data/features'; @@ -97,6 +99,8 @@ const defaultTemplates = { plainHtml: makeAdditionalTemplate('Plain HTML', plainHtmlTemplate), styledHtml: makeAdditionalTemplate('Styled HTML', styledHtmlTemplate), styledHtmlWithToc: makeAdditionalTemplate('Styled HTML with TOC', styledHtmlWithTocTemplate), + styledHtmlWithTheme: makeAdditionalTemplate('Styled HTML with Theme', styledHtmlWithThemeTemplate), + styledHtmlWithThemeAndToc: makeAdditionalTemplate('Styled HTML with Theme And TOC', styledHtmlWithThemeAndTocTemplate), jekyllSite: makeAdditionalTemplate('Jekyll site', jekyllSiteTemplate), };