{
+ const url = `${HLJS_CDN_BASE}/styles/${themeName}.min.css`;
+ try {
+ const res = await fetch(url);
+ if (!res.ok) {
+ console.error(`Failed to fetch code theme CSS: ${res.status} ${url}`);
+ return "";
+ }
+ return await res.text();
+ } catch (error) {
+ console.error(`Failed to fetch code theme CSS from ${url}:`, error);
+ return "";
+ }
+}
+
interface HtmlDocumentMeta {
title: string;
author?: string;
description?: string;
}
-function buildHtmlDocument(meta: HtmlDocumentMeta, css: string, html: string): string {
+function buildHtmlDocument(meta: HtmlDocumentMeta, css: string, html: string, codeThemeCss?: string): string {
const lines = [
"",
"",
@@ -729,8 +940,11 @@ function buildHtmlDocument(meta: HtmlDocumentMeta, css: string, html: string): s
if (meta.description) {
lines.push(` `);
}
+ lines.push(` `);
+ if (codeThemeCss) {
+ lines.push(` `);
+ }
lines.push(
- ` `,
"",
"",
' ',
@@ -758,12 +972,12 @@ async function inlineCss(html: string): Promise {
}
}
-function normalizeCssText(cssText: string): string {
+function normalizeCssText(cssText: string, style: StyleConfig = DEFAULT_STYLE): string {
return cssText
- .replace(/var\(--md-primary-color\)/g, DEFAULT_STYLE.primaryColor)
- .replace(/var\(--md-font-family\)/g, DEFAULT_STYLE.fontFamily)
- .replace(/var\(--md-font-size\)/g, DEFAULT_STYLE.fontSize)
- .replace(/var\(--blockquote-background\)/g, DEFAULT_STYLE.blockquoteBackground)
+ .replace(/var\(--md-primary-color\)/g, style.primaryColor)
+ .replace(/var\(--md-font-family\)/g, style.fontFamily)
+ .replace(/var\(--md-font-size\)/g, style.fontSize)
+ .replace(/var\(--blockquote-background\)/g, style.blockquoteBackground)
.replace(/hsl\(var\(--foreground\)\)/g, "#3f3f3f")
.replace(/--md-primary-color:\s*[^;"']+;?/g, "")
.replace(/--md-font-family:\s*[^;"']+;?/g, "")
@@ -772,20 +986,20 @@ function normalizeCssText(cssText: string): string {
.replace(/--foreground:\s*[^;"']+;?/g, "");
}
-function normalizeInlineCss(html: string): string {
+function normalizeInlineCss(html: string, style: StyleConfig = DEFAULT_STYLE): string {
let output = html;
output = output.replace(
/`
+ ``
);
output = output.replace(
/style="([^"]*)"/gi,
- (_match, cssText: string) => `style="${normalizeCssText(cssText)}"`
+ (_match, cssText: string) => `style="${normalizeCssText(cssText, style)}"`
);
output = output.replace(
/style='([^']*)'/gi,
- (_match, cssText: string) => `style='${normalizeCssText(cssText)}'`
+ (_match, cssText: string) => `style='${normalizeCssText(cssText, style)}'`
);
return output;
}
@@ -824,11 +1038,27 @@ async function main(): Promise {
options.inputPath.replace(/\.md$/i, ".html")
);
+ const style: StyleConfig = {
+ ...DEFAULT_STYLE,
+ primaryColor: options.primaryColor,
+ fontFamily: options.fontFamily,
+ fontSize: options.fontSize,
+ };
+
const { baseCss, themeCss } = loadThemeCss(options.theme);
- const css = normalizeThemeCss(buildCss(baseCss, themeCss));
+ const css = normalizeThemeCss(buildCss(baseCss, themeCss, style));
+
+ const codeThemeCss = await fetchCodeThemeCss(options.codeTheme);
+
const markdown = fs.readFileSync(inputPath, "utf-8");
- const renderer = initRenderer({});
+ const renderer = initRenderer({
+ legend: options.legend,
+ citeStatus: options.citeStatus,
+ countStatus: options.countStatus,
+ isMacCodeBlock: options.isMacCodeBlock,
+ isShowLineNumber: options.isShowLineNumber,
+ });
const { yamlData } = renderer.parseFrontMatterAndContent(markdown);
const { html: baseHtml, readingTime: readingTimeResult } = renderMarkdown(
markdown,
@@ -855,8 +1085,8 @@ async function main(): Promise {
author: stripQuotes(yamlData.author),
description: stripQuotes(yamlData.description) || stripQuotes(yamlData.summary),
};
- const html = buildHtmlDocument(meta, css, content);
- const inlinedHtml = normalizeInlineCss(await inlineCss(html));
+ const html = buildHtmlDocument(meta, css, content, codeThemeCss);
+ const inlinedHtml = normalizeInlineCss(await inlineCss(html), style);
const finalHtml = modifyHtmlStructure(inlinedHtml);
let backupPath = "";
diff --git a/skills/baoyu-markdown-to-html/scripts/md/themes/base.css b/skills/baoyu-markdown-to-html/scripts/md/themes/base.css
index 51ea92b..3ec1fe4 100644
--- a/skills/baoyu-markdown-to-html/scripts/md/themes/base.css
+++ b/skills/baoyu-markdown-to-html/scripts/md/themes/base.css
@@ -32,3 +32,8 @@ blockquote {
#output section > :first-child {
margin-top: 0 !important;
}
+
+.mermaid-diagram .nodeLabel p {
+ color: unset !important;
+ letter-spacing: unset !important;
+}
diff --git a/skills/baoyu-markdown-to-html/scripts/md/themes/default.css b/skills/baoyu-markdown-to-html/scripts/md/themes/default.css
index e30fcbf..b9982f6 100644
--- a/skills/baoyu-markdown-to-html/scripts/md/themes/default.css
+++ b/skills/baoyu-markdown-to-html/scripts/md/themes/default.css
@@ -269,6 +269,7 @@ pre.code__pre,
padding: 0 !important;
line-height: 1.5;
margin: 10px 8px;
+ box-shadow: inset 0 0 10px rgba(0,0,0,0.05);
}
/* ==================== 图片 ==================== */
diff --git a/skills/baoyu-markdown-to-html/scripts/md/themes/orange.css b/skills/baoyu-markdown-to-html/scripts/md/themes/orange.css
index 70d4fcc..6fb764c 100644
--- a/skills/baoyu-markdown-to-html/scripts/md/themes/orange.css
+++ b/skills/baoyu-markdown-to-html/scripts/md/themes/orange.css
@@ -114,6 +114,7 @@ blockquote > p {
pre.code__pre,
.hljs.code__pre {
border-radius: 10px;
+ box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
}
/* ==================== 图片 ==================== */
diff --git a/skills/baoyu-markdown-to-html/scripts/md/themes/red.css b/skills/baoyu-markdown-to-html/scripts/md/themes/red.css
index 32e8747..2e88e79 100644
--- a/skills/baoyu-markdown-to-html/scripts/md/themes/red.css
+++ b/skills/baoyu-markdown-to-html/scripts/md/themes/red.css
@@ -114,6 +114,7 @@ pre.code__pre,
.hljs.code__pre {
font-size: 13px;
border: 1px solid #D4AC0D;
+ box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
}
/* ==================== 图片 ==================== */