@wenyan-md/core 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +17 -2
  2. package/dist/atom-one-dark.min-Du_gemwz.js +4 -0
  3. package/dist/atom-one-light.min-BameqVOr.js +4 -0
  4. package/dist/browser/wenyan-core.js +53 -53
  5. package/dist/core.js +431 -272
  6. package/dist/default-CE6XHgHa.js +4 -0
  7. package/dist/dracula.min-DhYK88zj.js +4 -0
  8. package/dist/github-dark.min-rUG1U3df.js +4 -0
  9. package/dist/github.min-DEfTaph9.js +4 -0
  10. package/dist/hltheme.js +29 -22
  11. package/dist/juejin_default-B6AI_viJ.js +4 -0
  12. package/dist/lapis-BpjqywsV.js +4 -0
  13. package/dist/maize-BqG2l24H.js +4 -0
  14. package/dist/math/wenyan-math.js +9 -40
  15. package/dist/medium_default-DtspuXEE.js +4 -0
  16. package/dist/monokai.min-BszscX_9.js +4 -0
  17. package/dist/orangeheart-CWqZ_gXQ.js +4 -0
  18. package/dist/{phycat-C5ES4IMt.js → phycat-BNJAZy4V.js} +2 -6
  19. package/dist/pie-CVpIzs7v.js +4 -0
  20. package/dist/publish.js +137 -345
  21. package/dist/purple-ObLhqJQS.js +4 -0
  22. package/dist/rainbow-C5PT3WBL.js +4 -0
  23. package/dist/solarized-dark.min-mpQq1Jcj.js +4 -0
  24. package/dist/solarized-light.min-C5Ersr9g.js +4 -0
  25. package/dist/styles/wenyan-styles.js +21 -40
  26. package/dist/theme.js +40 -33
  27. package/dist/toutiao_default-BQ7BN6_-.js +4 -0
  28. package/dist/types/core.d.ts +17 -0
  29. package/dist/types/publish.d.ts +1 -1
  30. package/dist/types/wechatApi.d.ts +1 -1
  31. package/dist/types/wrapper.d.ts +3 -3
  32. package/dist/wrapper.js +15 -10
  33. package/dist/xcode.min-DWdHLdoo.js +4 -0
  34. package/dist/zhihu_default-DUBy_Cqy.js +4 -0
  35. package/package.json +5 -3
  36. package/dist/atom-one-dark.min-hABhDLRj.js +0 -4
  37. package/dist/atom-one-light.min-CwiVhPEv.js +0 -4
  38. package/dist/default-D-dyLptq.js +0 -184
  39. package/dist/dracula.min-OeyC4Nkp.js +0 -11
  40. package/dist/github-dark.min-DOlD5Ewr.js +0 -13
  41. package/dist/github.min-BZ2GvPsn.js +0 -14
  42. package/dist/juejin_default-CnUAGV72.js +0 -139
  43. package/dist/lapis-dRySN5pK.js +0 -194
  44. package/dist/maize-DFW0x6O3.js +0 -194
  45. package/dist/medium_default-BXHGUKdY.js +0 -135
  46. package/dist/monokai.min-CH2iHqHz.js +0 -4
  47. package/dist/orangeheart-Da7uQj8U.js +0 -184
  48. package/dist/pie-DUYodGli.js +0 -240
  49. package/dist/purple-Da1-Vfos.js +0 -183
  50. package/dist/rainbow-BtrbZco6.js +0 -167
  51. package/dist/solarized-dark.min-BxbYljx4.js +0 -11
  52. package/dist/solarized-light.min-Bb25xgOC.js +0 -11
  53. package/dist/toutiao_default-DthFV93V.js +0 -151
  54. package/dist/xcode.min-CG-lWQgl.js +0 -4
  55. package/dist/zhihu_default-7uVAZjKn.js +0 -138
package/dist/core.js CHANGED
@@ -1,350 +1,509 @@
1
- import { marked as g } from "marked";
2
- import { markedHighlight as H } from "marked-highlight";
3
- import x from "highlight.js";
4
- import P from "front-matter";
5
- import * as f from "css-tree";
6
- import { mathjax as j } from "mathjax-full/js/mathjax.js";
7
- import { TeX as V } from "mathjax-full/js/input/tex.js";
8
- import { SVG as q } from "mathjax-full/js/output/svg.js";
9
- import { liteAdaptor as I } from "mathjax-full/js/adaptors/liteAdaptor.js";
10
- import { RegisterHTMLHandler as k } from "mathjax-full/js/handlers/html.js";
11
- import { AllPackages as R } from "mathjax-full/js/input/tex/AllPackages.js";
12
- import { themes as b } from "./theme.js";
13
- import { hlThemes as C } from "./hltheme.js";
14
- const z = {
15
- inlineMath: [["$", "$"], ["\\(", "\\)"]],
16
- displayMath: [["$$", "$$"], ["\\[", "\\]"]],
17
- processEscapes: !0,
18
- packages: R
19
- }, D = {
1
+ import { marked } from "marked";
2
+ import { markedHighlight } from "marked-highlight";
3
+ import hljs from "highlight.js";
4
+ import fm from "front-matter";
5
+ import * as csstree from "css-tree";
6
+ import { mathjax } from "mathjax-full/js/mathjax.js";
7
+ import { TeX } from "mathjax-full/js/input/tex.js";
8
+ import { SVG } from "mathjax-full/js/output/svg.js";
9
+ import { liteAdaptor } from "mathjax-full/js/adaptors/liteAdaptor.js";
10
+ import { RegisterHTMLHandler } from "mathjax-full/js/handlers/html.js";
11
+ import { AllPackages } from "mathjax-full/js/input/tex/AllPackages.js";
12
+ import { themes } from "./theme.js";
13
+ import { hlThemes } from "./hltheme.js";
14
+ const texConfig = {
15
+ inlineMath: [
16
+ ["$", "$"],
17
+ ["\\(", "\\)"]
18
+ ],
19
+ displayMath: [
20
+ ["$$", "$$"],
21
+ ["\\[", "\\]"]
22
+ ],
23
+ processEscapes: true,
24
+ packages: AllPackages
25
+ };
26
+ const svgConfig = {
20
27
  fontCache: "none"
21
28
  };
22
- let m;
23
- if (!m) {
24
- m = I();
29
+ let adaptor;
30
+ if (!adaptor) {
31
+ adaptor = liteAdaptor();
25
32
  try {
26
- k(m);
27
- } catch {
33
+ RegisterHTMLHandler(adaptor);
34
+ } catch (e) {
28
35
  }
29
36
  }
30
- k(m);
31
- const E = new V(z), N = new q(D);
32
- function A(t, i) {
33
- const l = t.display ? "section" : "span", o = t.display ? "block-equation" : "inline-equation";
34
- t.typesetRoot = i.adaptor.node(l, { class: o }, [t.typesetRoot]);
37
+ RegisterHTMLHandler(adaptor);
38
+ const tex = new TeX(texConfig);
39
+ const svg = new SVG(svgConfig);
40
+ function addContainer(math, doc) {
41
+ const tag = math.display ? "section" : "span";
42
+ const cls = math.display ? "block-equation" : "inline-equation";
43
+ const container = math.typesetRoot;
44
+ if (math.math) {
45
+ doc.adaptor.setAttribute(container, "math", math.math);
46
+ }
47
+ const node = doc.adaptor.node(tag, { class: cls }, [container]);
48
+ math.typesetRoot = node;
35
49
  }
36
- async function F(t) {
50
+ async function renderMathInHtml(htmlString) {
37
51
  try {
38
- const i = j.document(t, {
39
- InputJax: E,
40
- OutputJax: N,
52
+ const html = mathjax.document(htmlString, {
53
+ InputJax: tex,
54
+ OutputJax: svg,
41
55
  renderActions: {
42
- addContainer: [190, (o) => {
43
- for (const r of o.math)
44
- A(r, o);
45
- }, A]
56
+ addContainer: [
57
+ 190,
58
+ (doc) => {
59
+ for (const math of doc.math) {
60
+ addContainer(math, doc);
61
+ }
62
+ },
63
+ addContainer
64
+ ]
46
65
  }
47
66
  });
48
- i.render();
49
- const l = m.body(i.document);
50
- return m.innerHTML(l);
51
- } catch (i) {
52
- throw console.error("Error rendering MathJax:", i), i;
67
+ html.render();
68
+ const body = adaptor.body(html.document);
69
+ return adaptor.innerHTML(body);
70
+ } catch (error) {
71
+ console.error("Error rendering MathJax:", error);
72
+ throw error;
53
73
  }
54
74
  }
55
- const G = `#wenyan pre::before {
75
+ const macStyleCss = `#wenyan pre::before {
56
76
  display: block;
57
77
  content: "";
58
78
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="45" height="12" viewBox="0 0 450 130"><ellipse cx="65" cy="65" rx="50" ry="52" stroke="rgb(220,60,54)" stroke-width="2" fill="rgb(237,108,96)"/><ellipse cx="225" cy="65" rx="50" ry="52" stroke="rgb(218,151,33)" stroke-width="2" fill="rgb(247,193,81)"/><ellipse cx="385" cy="65" rx="50" ry="52" stroke="rgb(27,161,37)" stroke-width="2" fill="rgb(100,200,86)"/></svg>');
59
79
  background-repeat: no-repeat;
60
80
  width: 100%;
61
81
  height: 16px;
62
- }`, ie = "ui-serif, Georgia, Cambria, 'Noto Serif', 'Times New Roman', serif", B = "ui-sans-serif, system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', 'Roboto', sans-serif", L = "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace";
63
- function le() {
64
- const t = H({
65
- emptyLangClass: "hljs",
66
- langPrefix: "hljs language-",
67
- highlight: function(r, s, a) {
68
- const e = x.getLanguage(s) ? s : "plaintext";
69
- return x.highlight(r, { language: e }).value;
70
- }
71
- });
72
- g.use(t);
73
- const i = {
74
- name: "attributeImage",
75
- level: "inline",
76
- start(r) {
77
- return r.indexOf("![");
78
- },
79
- tokenizer(r) {
80
- const a = /^!\[([^\]]*)\]\(([^)]+)\)\{(.*?)\}/.exec(r);
81
- if (a)
82
- return {
83
- type: "attributeImage",
84
- raw: a[0],
85
- alt: a[1],
86
- href: a[2],
87
- attrs: a[3]
88
- };
89
- },
90
- renderer(r) {
91
- const s = J(r.attrs), a = Array.from(s).map(
92
- ([e, n]) => /^\d+$/.test(n) ? `${e}:${n}px` : `${e}:${n}`
93
- ).join("; ");
94
- return `<img src="${r.href}" alt="${r.alt || ""}" title="${r.alt || ""}" style="${a}">`;
95
- }
96
- };
97
- g.use({ extensions: [i] });
98
- const l = g.Renderer, o = g.Parser;
99
- l.heading = function(r) {
100
- const s = o.parseInline(r.tokens), a = r.depth;
101
- return `<h${a}><span>${s}</span></h${a}>
82
+ }`;
83
+ const serif = "Georgia, Cambria, 'Noto Serif', 'Times New Roman', serif";
84
+ const sansSerif = "system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', 'Roboto', sans-serif";
85
+ const monospace = "Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace";
86
+ let markedConfigured = false;
87
+ let configurePromise = null;
88
+ async function configureMarked() {
89
+ if (markedConfigured) return;
90
+ if (configurePromise) return configurePromise;
91
+ configurePromise = (async () => {
92
+ const highlightExtension = markedHighlight({
93
+ emptyLangClass: "hljs",
94
+ langPrefix: "hljs language-",
95
+ highlight: function(code, lang, info) {
96
+ const language = hljs.getLanguage(lang) ? lang : "plaintext";
97
+ return hljs.highlight(code, { language }).value;
98
+ }
99
+ });
100
+ marked.use(highlightExtension);
101
+ const attributeImageExtension = {
102
+ name: "attributeImage",
103
+ level: "inline",
104
+ start(src) {
105
+ return src.indexOf("![");
106
+ },
107
+ tokenizer(src) {
108
+ const rule = /^!\[([^\]]*)\]\(([^)]+)\)\{(.*?)\}/;
109
+ const match = rule.exec(src);
110
+ if (match) {
111
+ return {
112
+ type: "attributeImage",
113
+ raw: match[0],
114
+ alt: match[1],
115
+ href: match[2],
116
+ attrs: match[3]
117
+ };
118
+ }
119
+ },
120
+ renderer(token) {
121
+ const attrs = stringToMap(token.attrs);
122
+ const attrStr = Array.from(attrs).map(
123
+ ([k, v]) => /^\d+$/.test(v) ? `${k}:${v}px` : `${k}:${v}`
124
+ ).join("; ");
125
+ return `<img src="${token.href}" alt="${token.alt || ""}" title="${token.alt || ""}" style="${attrStr}">`;
126
+ }
127
+ };
128
+ marked.use({ extensions: [attributeImageExtension] });
129
+ const renderer = marked.Renderer;
130
+ const parser = marked.Parser;
131
+ renderer.heading = function(heading) {
132
+ const text = parser.parseInline(heading.tokens);
133
+ const level = heading.depth;
134
+ return `<h${level}><span>${text}</span></h${level}>
135
+ `;
136
+ };
137
+ renderer.paragraph = function(paragraph) {
138
+ const text = paragraph.text;
139
+ if (text.length > 4 && (/\$\$[\s\S]*?\$\$/g.test(text) || /\\\[[\s\S]*?\\\]/g.test(text))) {
140
+ return `${text}
102
141
  `;
103
- }, l.paragraph = function(r) {
104
- const s = r.text;
105
- return s.length > 4 && (/\$\$[\s\S]*?\$\$/g.test(s) || /\\\[[\s\S]*?\\\]/g.test(s)) ? `${s}
106
- ` : `<p>${o.parseInline(r.tokens)}</p>
142
+ } else {
143
+ return `<p>${parser.parseInline(paragraph.tokens)}</p>
107
144
  `;
108
- }, l.image = function(r, s, a) {
109
- return `<img src="${r.href}" alt="${r.text || ""}" title="${r.text || ""}">`;
110
- }, g.use({ renderer: l });
145
+ }
146
+ };
147
+ renderer.image = function(token, title, text) {
148
+ const src = token.href;
149
+ return `<img src="${src}" alt="${token.text || ""}" title="${token.text || ""}">`;
150
+ };
151
+ marked.use({ renderer });
152
+ markedConfigured = true;
153
+ })();
154
+ return configurePromise;
111
155
  }
112
- function J(t) {
113
- const i = /* @__PURE__ */ new Map();
114
- return t.split(/\s+/).forEach((l) => {
115
- const [o, r] = l.split("=");
116
- o && r && i.set(o, r.replace(/^["']|["']$/g, ""));
117
- }), i;
156
+ function stringToMap(str) {
157
+ const map = /* @__PURE__ */ new Map();
158
+ str.split(/\s+/).forEach((pair) => {
159
+ const [key, value] = pair.split("=");
160
+ if (key && value) {
161
+ map.set(key, value.replace(/^["']|["']$/g, ""));
162
+ }
163
+ });
164
+ return map;
118
165
  }
119
- function ce(t) {
120
- const { attributes: i, body: l } = P(t), o = {};
121
- let r = "";
122
- const { title: s, description: a, cover: e } = i;
123
- return s && (o.title = s), a && (r += "> " + a + `
124
-
125
- `, o.description = a), e && (o.cover = e), o.body = r + l, o;
166
+ async function handleFrontMatter(markdown) {
167
+ const { attributes, body } = fm(markdown);
168
+ const result = {};
169
+ let head = "";
170
+ const { title, description, cover } = attributes;
171
+ if (title) {
172
+ result.title = title;
173
+ }
174
+ if (description) {
175
+ head += "> " + description + "\n\n";
176
+ result.description = description;
177
+ }
178
+ if (cover) {
179
+ result.cover = cover;
180
+ }
181
+ result.body = head + body;
182
+ return result;
126
183
  }
127
- async function pe(t) {
128
- const i = g.parse(t);
129
- return await F(i);
184
+ async function renderMarkdown(content) {
185
+ await configureMarked();
186
+ const html = marked.parse(content);
187
+ const htmlWithMath = await renderMathInHtml(html);
188
+ return htmlWithMath;
130
189
  }
131
- async function fe(t, i, l, o = !0, r = !0) {
132
- let s = b.default;
133
- if (i && (s = b[i], s || (s = Object.values(b).find(
134
- (c) => c.name.toLowerCase() === i.toLowerCase()
135
- ))), !s)
190
+ async function getContentForGzhBuiltinTheme(wenyanElement, themeId, hlThemeId, isMacStyle = true, isAddFootnote = true) {
191
+ let theme = themes["default"];
192
+ if (themeId) {
193
+ theme = themes[themeId];
194
+ if (!theme) {
195
+ theme = Object.values(themes).find(
196
+ (t) => t.name.toLowerCase() === themeId.toLowerCase()
197
+ );
198
+ }
199
+ }
200
+ if (!theme) {
136
201
  throw new Error("主题不存在");
137
- if (!(l in C))
202
+ }
203
+ if (!(hlThemeId in hlThemes)) {
138
204
  throw new Error("代码块主题不存在");
139
- const a = U(await s.getCss()), n = await C[l].getCss();
140
- return O(t, a, n, o, r);
205
+ }
206
+ const customCss = replaceCSSVariables(await theme.getCss());
207
+ const hlTheme = hlThemes[hlThemeId];
208
+ const highlightCss = await hlTheme.getCss();
209
+ return getContentForGzhCustomCss(wenyanElement, customCss, highlightCss, isMacStyle, isAddFootnote);
141
210
  }
142
- async function O(t, i, l, o = !0, r = !0) {
143
- r && Y(!1, t), i = W(i, {
211
+ async function getContentForGzhCustomCss(wenyanElement, customCss, highlightCss, isMacStyle = true, isAddFootnote = true) {
212
+ if (isAddFootnote) {
213
+ addFootnotes(false, wenyanElement);
214
+ }
215
+ customCss = modifyCss(customCss, {
144
216
  "#wenyan pre code": [
145
217
  {
146
218
  property: "font-family",
147
- value: L,
148
- append: !0
219
+ value: monospace,
220
+ append: true
149
221
  }
150
222
  ],
151
223
  "#wenyan pre": [
152
224
  {
153
225
  property: "font-size",
154
226
  value: "12px",
155
- append: !0
227
+ append: true
156
228
  }
157
229
  ]
158
230
  });
159
- const s = f.parse(i, {
231
+ const ast = csstree.parse(customCss, {
160
232
  context: "stylesheet",
161
- positions: !1,
162
- parseAtrulePrelude: !1,
163
- parseCustomProperty: !1,
164
- parseValue: !1
165
- }), a = f.parse(l, {
233
+ positions: false,
234
+ parseAtrulePrelude: false,
235
+ parseCustomProperty: false,
236
+ parseValue: false
237
+ });
238
+ const ast1 = csstree.parse(highlightCss, {
166
239
  context: "stylesheet",
167
- positions: !1,
168
- parseAtrulePrelude: !1,
169
- parseCustomProperty: !1,
170
- parseValue: !1
240
+ positions: false,
241
+ parseAtrulePrelude: false,
242
+ parseCustomProperty: false,
243
+ parseValue: false
171
244
  });
172
- if (s.children.appendList(a.children), o) {
173
- const n = f.parse(G, {
245
+ ast.children.appendList(ast1.children);
246
+ if (isMacStyle) {
247
+ const ast2 = csstree.parse(macStyleCss, {
174
248
  context: "stylesheet",
175
- positions: !1,
176
- parseAtrulePrelude: !1,
177
- parseCustomProperty: !1,
178
- parseValue: !1
249
+ positions: false,
250
+ parseAtrulePrelude: false,
251
+ parseCustomProperty: false,
252
+ parseValue: false
179
253
  });
180
- s.children.appendList(n.children);
254
+ ast.children.appendList(ast2.children);
181
255
  }
182
- f.walk(s, {
256
+ csstree.walk(ast, {
183
257
  visit: "Rule",
184
- enter(n, c, p) {
185
- const u = n.prelude.children;
186
- u && u.forEach((d) => {
187
- const h = f.generate(d), $ = n.block.children.toArray();
188
- h === "#wenyan" ? $.forEach((y) => {
189
- const v = f.generate(y.value);
190
- t.style[y.property] = v;
191
- }) : t.querySelectorAll(h).forEach((v) => {
192
- $.forEach((w) => {
193
- const T = f.generate(w.value);
194
- v.style[w.property] = T;
195
- });
258
+ enter(node, item, list) {
259
+ const selectorList = node.prelude.children;
260
+ if (selectorList) {
261
+ selectorList.forEach((selectorNode) => {
262
+ const selector = csstree.generate(selectorNode);
263
+ const declarations = node.block.children.toArray();
264
+ if (selector === "#wenyan") {
265
+ declarations.forEach((decl) => {
266
+ const value = csstree.generate(decl.value);
267
+ wenyanElement.style[decl.property] = value;
268
+ });
269
+ } else {
270
+ const elements2 = wenyanElement.querySelectorAll(selector);
271
+ elements2.forEach((element) => {
272
+ declarations.forEach((decl) => {
273
+ const value = csstree.generate(decl.value);
274
+ element.style[decl.property] = value;
275
+ });
276
+ });
277
+ }
196
278
  });
197
- });
279
+ }
280
+ }
281
+ });
282
+ let elements = wenyanElement.querySelectorAll("mjx-container");
283
+ elements.forEach((element) => {
284
+ const svg2 = element.querySelector("svg");
285
+ svg2.style.width = svg2.getAttribute("width");
286
+ svg2.style.height = svg2.getAttribute("height");
287
+ svg2.removeAttribute("width");
288
+ svg2.removeAttribute("height");
289
+ const parent = element.parentElement;
290
+ element.remove();
291
+ parent.appendChild(svg2);
292
+ if (parent.classList.contains("block-equation")) {
293
+ parent.setAttribute("style", "text-align: center; margin-bottom: 1rem;");
198
294
  }
199
295
  });
200
- let e = t.querySelectorAll("mjx-container");
201
- return e.forEach((n) => {
202
- const c = n.querySelector("svg");
203
- c.style.width = c.getAttribute("width"), c.style.height = c.getAttribute("height"), c.removeAttribute("width"), c.removeAttribute("height");
204
- const p = n.parentElement;
205
- n.remove(), p.appendChild(c), p.classList.contains("block-equation") && p.setAttribute("style", "text-align: center; margin-bottom: 1rem;");
206
- }), e = t.querySelectorAll("pre code"), e.forEach((n) => {
207
- n.innerHTML = n.innerHTML.replace(/\n/g, "<br>").replace(/(>[^<]+)|(^[^<]+)/g, (c) => c.replace(/\s/g, "&nbsp;"));
208
- }), e = t.querySelectorAll("h1, h2, h3, h4, h5, h6, blockquote, pre"), e.forEach((n) => {
209
- const c = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
210
- f.walk(s, {
296
+ elements = wenyanElement.querySelectorAll("pre code");
297
+ elements.forEach((element) => {
298
+ element.innerHTML = element.innerHTML.replace(/\n/g, "<br>").replace(/(>[^<]+)|(^[^<]+)/g, (str) => str.replace(/\s/g, "&nbsp;"));
299
+ });
300
+ elements = wenyanElement.querySelectorAll("h1, h2, h3, h4, h5, h6, blockquote, pre");
301
+ elements.forEach((element) => {
302
+ const afterResults = /* @__PURE__ */ new Map();
303
+ const beforeResults = /* @__PURE__ */ new Map();
304
+ csstree.walk(ast, {
211
305
  visit: "Rule",
212
- enter(u) {
213
- const d = f.generate(u.prelude), h = n.tagName.toLowerCase();
214
- d.includes(`${h}::after`) ? M(u, c) : d.includes(`${h}::before`) && M(u, p);
306
+ enter(node) {
307
+ const selector = csstree.generate(node.prelude);
308
+ const tagName = element.tagName.toLowerCase();
309
+ if (selector.includes(`${tagName}::after`)) {
310
+ extractDeclarations(node, afterResults);
311
+ } else if (selector.includes(`${tagName}::before`)) {
312
+ extractDeclarations(node, beforeResults);
313
+ }
215
314
  }
216
- }), c.size > 0 && n.appendChild(S(c, t.ownerDocument)), p.size > 0 && n.insertBefore(S(p, t.ownerDocument), n.firstChild);
217
- }), e = t.querySelectorAll("li"), e.forEach((n) => {
218
- const c = t.ownerDocument.createElement("section");
219
- for (; n.firstChild; )
220
- c.appendChild(n.firstChild);
221
- n.appendChild(c);
222
- }), t.setAttribute("data-provider", "WenYan"), `${t.outerHTML.replace(/class="mjx-solid"/g, 'fill="none" stroke-width="70"')}`;
315
+ });
316
+ if (afterResults.size > 0) {
317
+ element.appendChild(buildPseudoSpan(afterResults, wenyanElement.ownerDocument));
318
+ }
319
+ if (beforeResults.size > 0) {
320
+ element.insertBefore(buildPseudoSpan(beforeResults, wenyanElement.ownerDocument), element.firstChild);
321
+ }
322
+ });
323
+ elements = wenyanElement.querySelectorAll("li");
324
+ elements.forEach((li) => {
325
+ const section = wenyanElement.ownerDocument.createElement("section");
326
+ while (li.firstChild) {
327
+ section.appendChild(li.firstChild);
328
+ }
329
+ li.appendChild(section);
330
+ });
331
+ wenyanElement.setAttribute("data-provider", "WenYan");
332
+ return `${wenyanElement.outerHTML.replace(/class="mjx-solid"/g, 'fill="none" stroke-width="70"')}`;
223
333
  }
224
- function U(t) {
225
- const i = /--([a-zA-Z0-9\-]+):\s*([^;()]*\((?:[^()]*|\([^()]*\))*\)[^;()]*|[^;]+);/g, l = /var\(--([a-zA-Z0-9\-]+)\)/g, o = {};
226
- let r;
227
- for (; (r = i.exec(t)) !== null; ) {
228
- const e = r[1], n = r[2].trim().replaceAll(`
229
- `, "");
230
- o[e] = n;
334
+ function replaceCSSVariables(css) {
335
+ const variablePattern = /--([a-zA-Z0-9\-]+):\s*([^;()]*\((?:[^()]*|\([^()]*\))*\)[^;()]*|[^;]+);/g;
336
+ const varPattern = /var\(--([a-zA-Z0-9\-]+)\)/g;
337
+ const cssVariables = {};
338
+ let match;
339
+ while ((match = variablePattern.exec(css)) !== null) {
340
+ const variableName = match[1];
341
+ const variableValue = match[2].trim().replaceAll("\n", "");
342
+ cssVariables[variableName] = variableValue;
231
343
  }
232
- o["sans-serif-font"] || (o["sans-serif-font"] = B), o["monospace-font"] || (o["monospace-font"] = L);
233
- function s(e, n, c = /* @__PURE__ */ new Set()) {
234
- if (c.has(e)) return e;
235
- c.add(e);
236
- let p = e, u;
237
- for (; (u = l.exec(p)) !== null; ) {
238
- const d = u[1];
239
- if (n[d]) {
240
- const h = s(n[d], n, c);
241
- p = p.replace(u[0], h);
344
+ if (!cssVariables["sans-serif-font"]) {
345
+ cssVariables["sans-serif-font"] = sansSerif;
346
+ }
347
+ if (!cssVariables["monospace-font"]) {
348
+ cssVariables["monospace-font"] = monospace;
349
+ }
350
+ function resolveVariable(value, variables, resolved = /* @__PURE__ */ new Set()) {
351
+ if (resolved.has(value)) return value;
352
+ resolved.add(value);
353
+ let resolvedValue = value;
354
+ let match2;
355
+ while ((match2 = varPattern.exec(resolvedValue)) !== null) {
356
+ const varName = match2[1];
357
+ if (variables[varName]) {
358
+ const resolvedVar = resolveVariable(variables[varName], variables, resolved);
359
+ resolvedValue = resolvedValue.replace(match2[0], resolvedVar);
242
360
  }
243
361
  }
244
- return p;
362
+ return resolvedValue;
245
363
  }
246
- for (const e in o) {
247
- const n = s(o[e], o);
248
- o[e] = n;
364
+ for (const key in cssVariables) {
365
+ const resolvedValue = resolveVariable(cssVariables[key], cssVariables);
366
+ cssVariables[key] = resolvedValue;
249
367
  }
250
- let a = t;
251
- for (; (r = l.exec(t)) !== null; ) {
252
- const e = r[1];
253
- o[e] && (a = a.replace(r[0], o[e]));
368
+ let modifiedCSS = css;
369
+ while ((match = varPattern.exec(css)) !== null) {
370
+ const varName = match[1];
371
+ if (cssVariables[varName]) {
372
+ modifiedCSS = modifiedCSS.replace(match[0], cssVariables[varName]);
373
+ }
254
374
  }
255
- return a.replace(/:root\s*\{[^}]*\}/g, "");
375
+ return modifiedCSS.replace(/:root\s*\{[^}]*\}/g, "");
256
376
  }
257
- function W(t, i) {
258
- const l = f.parse(t, {
377
+ function modifyCss(customCss, updates) {
378
+ const ast = csstree.parse(customCss, {
259
379
  context: "stylesheet",
260
- positions: !1,
261
- parseAtrulePrelude: !1,
262
- parseCustomProperty: !1,
263
- parseValue: !1
380
+ positions: false,
381
+ parseAtrulePrelude: false,
382
+ parseCustomProperty: false,
383
+ parseValue: false
264
384
  });
265
- return f.walk(l, {
385
+ csstree.walk(ast, {
266
386
  visit: "Rule",
267
- leave: (o, r, s) => {
268
- if (o.prelude.type !== "SelectorList") return;
269
- const a = o.prelude.children.toArray().map((e) => f.generate(e));
270
- if (a) {
271
- const e = a[0], n = i[e];
272
- if (!n) return;
273
- for (const { property: c, value: p, append: u } of n)
274
- if (p) {
275
- let d = !1;
276
- f.walk(o.block, (h) => {
277
- h.type === "Declaration" && h.property === c && (h.value = f.parse(p, { context: "value" }), d = !0);
278
- }), !d && u && o.block.children.prepend(
279
- s.createItem({
280
- type: "Declaration",
281
- property: c,
282
- value: f.parse(p, { context: "value" })
283
- })
284
- );
387
+ leave: (node, item, list) => {
388
+ if (node.prelude.type !== "SelectorList") return;
389
+ const selectors = node.prelude.children.toArray().map((sel) => csstree.generate(sel));
390
+ if (selectors) {
391
+ const selector = selectors[0];
392
+ const update = updates[selector];
393
+ if (!update) return;
394
+ for (const { property, value, append } of update) {
395
+ if (value) {
396
+ let found = false;
397
+ csstree.walk(node.block, (decl) => {
398
+ if (decl.type === "Declaration" && decl.property === property) {
399
+ decl.value = csstree.parse(value, { context: "value" });
400
+ found = true;
401
+ }
402
+ });
403
+ if (!found && append) {
404
+ node.block.children.prepend(
405
+ list.createItem({
406
+ type: "Declaration",
407
+ property,
408
+ value: csstree.parse(value, { context: "value" })
409
+ })
410
+ );
411
+ }
285
412
  }
413
+ }
286
414
  }
287
415
  }
288
- }), f.generate(l);
416
+ });
417
+ return csstree.generate(ast);
289
418
  }
290
- function M(t, i) {
291
- f.walk(t.block, {
419
+ function extractDeclarations(ruleNode, resultMap) {
420
+ csstree.walk(ruleNode.block, {
292
421
  visit: "Declaration",
293
- enter(l) {
294
- const o = l.property, r = f.generate(l.value);
295
- i.set(o, r);
422
+ enter(declNode) {
423
+ const property = declNode.property;
424
+ const value = csstree.generate(declNode.value);
425
+ resultMap.set(property, value);
296
426
  }
297
427
  });
298
428
  }
299
- function S(t, i) {
300
- const l = i.createElement("section");
301
- t.get("content") && (l.textContent = t.get("content").replace(/['"]/g, ""), t.delete("content"));
302
- for (const [s, a] of t)
303
- if (a.includes("url(")) {
304
- const e = a.match(/data:image\/svg\+xml;utf8,(.*<\/svg>)/), n = a.match(/data:image\/svg\+xml;base64,([^"'\)]*)["']?\)/), c = a.match(/(?:"|')?(https?[^"'\)]*)(?:"|')?\)/);
305
- if (e) {
306
- const p = decodeURIComponent(e[1]);
307
- l.innerHTML = p;
308
- } else if (n) {
309
- const p = atob(n[1]);
310
- l.innerHTML = p;
311
- } else if (c) {
312
- const p = i.createElement("img");
313
- p.src = c[1], p.setAttribute("style", "vertical-align: top;"), l.appendChild(p);
429
+ function buildPseudoSpan(beforeRresults, document) {
430
+ const span = document.createElement("section");
431
+ if (beforeRresults.get("content")) {
432
+ span.textContent = beforeRresults.get("content").replace(/['"]/g, "");
433
+ beforeRresults.delete("content");
434
+ }
435
+ for (const [k, v] of beforeRresults) {
436
+ if (v.includes("url(")) {
437
+ const svgMatch = v.match(/data:image\/svg\+xml;utf8,(.*<\/svg>)/);
438
+ const base64SvgMatch = v.match(/data:image\/svg\+xml;base64,([^"'\)]*)["']?\)/);
439
+ const httpMatch = v.match(/(?:"|')?(https?[^"'\)]*)(?:"|')?\)/);
440
+ if (svgMatch) {
441
+ const svgCode = decodeURIComponent(svgMatch[1]);
442
+ span.innerHTML = svgCode;
443
+ } else if (base64SvgMatch) {
444
+ const decodedString = atob(base64SvgMatch[1]);
445
+ span.innerHTML = decodedString;
446
+ } else if (httpMatch) {
447
+ const img = document.createElement("img");
448
+ img.src = httpMatch[1];
449
+ img.setAttribute("style", "vertical-align: top;");
450
+ span.appendChild(img);
314
451
  }
315
- t.delete(s);
452
+ beforeRresults.delete(k);
316
453
  }
317
- const r = Array.from(t.entries()).map(([s, a]) => `${s}: ${a}`).join("; ");
318
- return l.style.cssText = r, l;
454
+ }
455
+ const entries = Array.from(beforeRresults.entries());
456
+ const cssString = entries.map(([key, value]) => `${key}: ${value}`).join("; ");
457
+ span.style.cssText = cssString;
458
+ return span;
319
459
  }
320
- function Y(t, i) {
321
- let l = [], o = 0;
322
- if (i.querySelectorAll("a[href]").forEach((s) => {
323
- const a = s.textContent || s.innerText, e = s.getAttribute("href");
324
- l.push([++o, a, e]);
325
- const n = i.ownerDocument.createElement("sup");
326
- n.setAttribute("class", "footnote"), n.innerHTML = `[${o}]`, s.after(n);
327
- }), o > 0)
328
- if (t) {
329
- const a = `<h3>引用链接</h3><div id="footnotes"><ul>${l.map((e) => e[1] === e[2] ? `<li id="#footnote-${e[0]}">[${e[0]}]: <i>${e[1]}</i></li>` : `<li id="#footnote-${e[0]}">[${e[0]}] ${e[1]}: <i>${e[2]}</i></li>`).join("")}</ul></div>`;
330
- i.innerHTML += a;
460
+ function addFootnotes(listStyle, element) {
461
+ let footnotes = [];
462
+ let footnoteIndex = 0;
463
+ const links = element.querySelectorAll("a[href]");
464
+ links.forEach((linkElement) => {
465
+ const title = linkElement.textContent || linkElement.innerText;
466
+ const href = linkElement.getAttribute("href");
467
+ footnotes.push([++footnoteIndex, title, href]);
468
+ const footnoteMarker = element.ownerDocument.createElement("sup");
469
+ footnoteMarker.setAttribute("class", "footnote");
470
+ footnoteMarker.innerHTML = `[${footnoteIndex}]`;
471
+ linkElement.after(footnoteMarker);
472
+ });
473
+ if (footnoteIndex > 0) {
474
+ if (!listStyle) {
475
+ let footnoteArray = footnotes.map((x) => {
476
+ if (x[1] === x[2]) {
477
+ return `<p><span class="footnote-num">[${x[0]}]</span><span class="footnote-txt"><i>${x[1]}</i></span></p>`;
478
+ }
479
+ return `<p><span class="footnote-num">[${x[0]}]</span><span class="footnote-txt">${x[1]}: <i>${x[2]}</i></span></p>`;
480
+ });
481
+ const footnotesHtml = `<h3>引用链接</h3><section id="footnotes">${footnoteArray.join("")}</section>`;
482
+ element.innerHTML += footnotesHtml;
331
483
  } else {
332
- const a = `<h3>引用链接</h3><section id="footnotes">${l.map((e) => e[1] === e[2] ? `<p><span class="footnote-num">[${e[0]}]</span><span class="footnote-txt"><i>${e[1]}</i></span></p>` : `<p><span class="footnote-num">[${e[0]}]</span><span class="footnote-txt">${e[1]}: <i>${e[2]}</i></span></p>`).join("")}</section>`;
333
- i.innerHTML += a;
484
+ let footnoteArray = footnotes.map((x) => {
485
+ if (x[1] === x[2]) {
486
+ return `<li id="#footnote-${x[0]}">[${x[0]}]: <i>${x[1]}</i></li>`;
487
+ }
488
+ return `<li id="#footnote-${x[0]}">[${x[0]}] ${x[1]}: <i>${x[2]}</i></li>`;
489
+ });
490
+ const footnotesHtml = `<h3>引用链接</h3><div id="footnotes"><ul>${footnoteArray.join("")}</ul></div>`;
491
+ element.innerHTML += footnotesHtml;
334
492
  }
493
+ }
335
494
  }
336
495
  export {
337
- Y as addFootnotes,
338
- S as buildPseudoSpan,
339
- le as configureMarked,
340
- M as extractDeclarations,
341
- fe as getContentForGzhBuiltinTheme,
342
- O as getContentForGzhCustomCss,
343
- ce as handleFrontMatter,
344
- W as modifyCss,
345
- L as monospace,
346
- pe as renderMarkdown,
347
- U as replaceCSSVariables,
348
- B as sansSerif,
349
- ie as serif
496
+ addFootnotes,
497
+ buildPseudoSpan,
498
+ configureMarked,
499
+ extractDeclarations,
500
+ getContentForGzhBuiltinTheme,
501
+ getContentForGzhCustomCss,
502
+ handleFrontMatter,
503
+ modifyCss,
504
+ monospace,
505
+ renderMarkdown,
506
+ replaceCSSVariables,
507
+ sansSerif,
508
+ serif
350
509
  };