@wenyan-md/core 1.0.11 → 1.0.12
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.
- package/README.md +5 -0
- package/dist/browser/wenyan-core.js +1 -1
- package/dist/core.js +102 -97
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
# 文颜 CORE
|
|
6
6
|
|
|
7
|
+
[](https://www.npmjs.com/package/@wenyan-md/core)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+
[](https://github.com/caol64/wenyan-core)
|
|
11
|
+
|
|
7
12
|
「文颜」是一款多平台排版美化工具,让你将 Markdown 一键发布至微信公众号、知乎、今日头条等主流写作平台。
|
|
8
13
|
|
|
9
14
|
**文颜**现已推出多个版本:
|
|
@@ -90,5 +90,5 @@ Please report this to https://github.com/markedjs/marked.`,r){const o="<p>An err
|
|
|
90
90
|
`:`<p>${o.parseInline(t.tokens)}</p>
|
|
91
91
|
`},i.image=function(t,a,s){return`<img src="${t.href}" alt="${t.text||""}" title="${t.text||""}">`},O.use({renderer:i})}function vi(r){const n=new Map;return r.split(/\s+/).forEach(i=>{const[o,t]=i.split("=");o&&t&&n.set(o,t.replace(/^["']|["']$/g,""))}),n}function bi(r){const{attributes:n,body:i}=mi(r),o={};let t="";const{title:a,description:s,cover:u}=n;return a&&(o.title=a),s&&(t+="> "+s+`
|
|
92
92
|
|
|
93
|
-
`,o.description=s),u&&(o.cover=u),o.body=t+i,o}async function yi(r){const n=O.parse(r);return await tt.renderMathInHtml(n)}async function wi(r,n,i,o=!0,t=!0){let a=Je.themes.default;if(n&&(a=Je.themes[n],a||(a=Object.values(Je.themes).find(p=>p.name.toLowerCase()===n.toLowerCase()))),!a)throw new Error("主题不存在");if(!(i in Kn.hlThemes))throw new Error("代码块主题不存在");const s=Xr(await a.getCss()),c=await Kn.hlThemes[i].getCss();return Jr(r,s,c,o,t)}async function Jr(r,n,i,o=!0,t=!0){t&&nt(!1,r),n=et(n,{"#wenyan pre code":[{property:"font-family",value:Pn,append:!0}],"#wenyan pre":[{property:"font-size",value:"12px",append:!0}]});const a=N.parse(n,{context:"stylesheet",positions:!1,parseAtrulePrelude:!1,parseCustomProperty:!1,parseValue:!1}),s=N.parse(i,{context:"stylesheet",positions:!1,parseAtrulePrelude:!1,parseCustomProperty:!1,parseValue:!1});if(a.children.appendList(s.children),o){const c=N.parse(it,{context:"stylesheet",positions:!1,parseAtrulePrelude:!1,parseCustomProperty:!1,parseValue:!1});a.children.appendList(c.children)}N.walk(a,{visit:"Rule",enter(c,p,f){const v=c.prelude.children;v&&v.forEach(x=>{const F=N.generate(x),_=c.block.children.toArray();F==="#wenyan"?_.forEach($=>{const H=N.generate($.value);r.style[$.property]=H}):r.querySelectorAll(F).forEach(H=>{_.forEach(Z=>{const K=N.generate(Z.value);H.style[Z.property]=K})})})}});let u=r.querySelectorAll("mjx-container");return u.forEach(c=>{const p=c.querySelector("svg");p.style.width=p.getAttribute("width"),p.style.height=p.getAttribute("height"),p.removeAttribute("width"),p.removeAttribute("height");const f=c.parentElement;c.remove(),f.appendChild(p),f.classList.contains("block-equation")&&f.setAttribute("style","text-align: center; margin-bottom: 1rem;")}),u=r.querySelectorAll("pre code"),u.forEach(c=>{c.innerHTML=c.innerHTML.replace(/\n/g,"<br>").replace(/(>[^<]+)|(^[^<]+)/g,p=>p.replace(/\s/g," "))}),u=r.querySelectorAll("h1, h2, h3, h4, h5, h6, blockquote, pre"),u.forEach(c=>{const p=new Map,f=new Map;N.walk(a,{visit:"Rule",enter(v){const x=N.generate(v.prelude),F=c.tagName.toLowerCase();x.includes(`${F}::after`)?qn(v,p):x.includes(`${F}::before`)&&qn(v,f)}}),p.size>0&&c.appendChild(Nn(p,r.ownerDocument)),f.size>0&&c.insertBefore(Nn(f,r.ownerDocument),c.firstChild)}),r.setAttribute("data-provider","WenYan"),`${r.outerHTML.replace(/class="mjx-solid"/g,'fill="none" stroke-width="70"')}`}function Xr(r){const n=/--([a-zA-Z0-9\-]+):\s*([^;()]*\((?:[^()]*|\([^()]*\))*\)[^;()]*|[^;]+);/g,i=/var\(--([a-zA-Z0-9\-]+)\)/g,o={};let t;for(;(t=n.exec(r))!==null;){const u=t[1],c=t[2].trim().replaceAll(`
|
|
93
|
+
`,o.description=s),u&&(o.cover=u),o.body=t+i,o}async function yi(r){const n=O.parse(r);return await tt.renderMathInHtml(n)}async function wi(r,n,i,o=!0,t=!0){let a=Je.themes.default;if(n&&(a=Je.themes[n],a||(a=Object.values(Je.themes).find(p=>p.name.toLowerCase()===n.toLowerCase()))),!a)throw new Error("主题不存在");if(!(i in Kn.hlThemes))throw new Error("代码块主题不存在");const s=Xr(await a.getCss()),c=await Kn.hlThemes[i].getCss();return Jr(r,s,c,o,t)}async function Jr(r,n,i,o=!0,t=!0){t&&nt(!1,r),n=et(n,{"#wenyan pre code":[{property:"font-family",value:Pn,append:!0}],"#wenyan pre":[{property:"font-size",value:"12px",append:!0}]});const a=N.parse(n,{context:"stylesheet",positions:!1,parseAtrulePrelude:!1,parseCustomProperty:!1,parseValue:!1}),s=N.parse(i,{context:"stylesheet",positions:!1,parseAtrulePrelude:!1,parseCustomProperty:!1,parseValue:!1});if(a.children.appendList(s.children),o){const c=N.parse(it,{context:"stylesheet",positions:!1,parseAtrulePrelude:!1,parseCustomProperty:!1,parseValue:!1});a.children.appendList(c.children)}N.walk(a,{visit:"Rule",enter(c,p,f){const v=c.prelude.children;v&&v.forEach(x=>{const F=N.generate(x),_=c.block.children.toArray();F==="#wenyan"?_.forEach($=>{const H=N.generate($.value);r.style[$.property]=H}):r.querySelectorAll(F).forEach(H=>{_.forEach(Z=>{const K=N.generate(Z.value);H.style[Z.property]=K})})})}});let u=r.querySelectorAll("mjx-container");return u.forEach(c=>{const p=c.querySelector("svg");p.style.width=p.getAttribute("width"),p.style.height=p.getAttribute("height"),p.removeAttribute("width"),p.removeAttribute("height");const f=c.parentElement;c.remove(),f.appendChild(p),f.classList.contains("block-equation")&&f.setAttribute("style","text-align: center; margin-bottom: 1rem;")}),u=r.querySelectorAll("pre code"),u.forEach(c=>{c.innerHTML=c.innerHTML.replace(/\n/g,"<br>").replace(/(>[^<]+)|(^[^<]+)/g,p=>p.replace(/\s/g," "))}),u=r.querySelectorAll("h1, h2, h3, h4, h5, h6, blockquote, pre"),u.forEach(c=>{const p=new Map,f=new Map;N.walk(a,{visit:"Rule",enter(v){const x=N.generate(v.prelude),F=c.tagName.toLowerCase();x.includes(`${F}::after`)?qn(v,p):x.includes(`${F}::before`)&&qn(v,f)}}),p.size>0&&c.appendChild(Nn(p,r.ownerDocument)),f.size>0&&c.insertBefore(Nn(f,r.ownerDocument),c.firstChild)}),u=r.querySelectorAll("li"),u.forEach(c=>{const p=r.ownerDocument.createElement("section");for(;c.firstChild;)p.appendChild(c.firstChild);c.appendChild(p)}),r.setAttribute("data-provider","WenYan"),`${r.outerHTML.replace(/class="mjx-solid"/g,'fill="none" stroke-width="70"')}`}function Xr(r){const n=/--([a-zA-Z0-9\-]+):\s*([^;()]*\((?:[^()]*|\([^()]*\))*\)[^;()]*|[^;]+);/g,i=/var\(--([a-zA-Z0-9\-]+)\)/g,o={};let t;for(;(t=n.exec(r))!==null;){const u=t[1],c=t[2].trim().replaceAll(`
|
|
94
94
|
`,"");o[u]=c}o["sans-serif-font"]||(o["sans-serif-font"]=Qr),o["monospace-font"]||(o["monospace-font"]=Pn);function a(u,c,p=new Set){if(p.has(u))return u;p.add(u);let f=u,v;for(;(v=i.exec(f))!==null;){const x=v[1];if(c[x]){const F=a(c[x],c,p);f=f.replace(v[0],F)}}return f}for(const u in o){const c=a(o[u],o);o[u]=c}let s=r;for(;(t=i.exec(r))!==null;){const u=t[1];o[u]&&(s=s.replace(t[0],o[u]))}return s.replace(/:root\s*\{[^}]*\}/g,"")}function et(r,n){const i=N.parse(r,{context:"stylesheet",positions:!1,parseAtrulePrelude:!1,parseCustomProperty:!1,parseValue:!1});return N.walk(i,{visit:"Rule",leave:(o,t,a)=>{if(o.prelude.type!=="SelectorList")return;const s=o.prelude.children.toArray().map(u=>N.generate(u));if(s){const u=s[0],c=n[u];if(!c)return;for(const{property:p,value:f,append:v}of c)if(f){let x=!1;N.walk(o.block,F=>{F.type==="Declaration"&&F.property===p&&(F.value=N.parse(f,{context:"value"}),x=!0)}),!x&&v&&o.block.children.prepend(a.createItem({type:"Declaration",property:p,value:N.parse(f,{context:"value"})}))}}}}),N.generate(i)}function qn(r,n){N.walk(r.block,{visit:"Declaration",enter(i){const o=i.property,t=N.generate(i.value);n.set(o,t)}})}function Nn(r,n){const i=n.createElement("section");r.get("content")&&(i.textContent=r.get("content").replace(/['"]/g,""),r.delete("content"));for(const[a,s]of r)if(s.includes("url(")){const u=s.match(/data:image\/svg\+xml;utf8,(.*<\/svg>)/),c=s.match(/data:image\/svg\+xml;base64,([^"'\)]*)["']?\)/),p=s.match(/(?:"|')?(https?[^"'\)]*)(?:"|')?\)/);if(u){const f=decodeURIComponent(u[1]);i.innerHTML=f}else if(c){const f=atob(c[1]);i.innerHTML=f}else if(p){const f=n.createElement("img");f.src=p[1],f.setAttribute("style","vertical-align: top;"),i.appendChild(f)}r.delete(a)}const t=Array.from(r.entries()).map(([a,s])=>`${a}: ${s}`).join("; ");return i.style.cssText=t,i}function nt(r,n){let i=[],o=0;if(n.querySelectorAll("a[href]").forEach(a=>{const s=a.textContent||a.innerText,u=a.getAttribute("href");i.push([++o,s,u]);const c=n.ownerDocument.createElement("sup");c.setAttribute("class","footnote"),c.innerHTML=`[${o}]`,a.after(c)}),o>0)if(r){const s=`<h3>引用链接</h3><div id="footnotes"><ul>${i.map(u=>u[1]===u[2]?`<li id="#footnote-${u[0]}">[${u[0]}]: <i>${u[1]}</i></li>`:`<li id="#footnote-${u[0]}">[${u[0]}] ${u[1]}: <i>${u[2]}</i></li>`).join("")}</ul></div>`;n.innerHTML+=s}else{const s=`<h3>引用链接</h3><section id="footnotes">${i.map(u=>u[1]===u[2]?`<p><span class="footnote-num">[${u[0]}]</span><span class="footnote-txt"><i>${u[1]}</i></span></p>`:`<p><span class="footnote-num">[${u[0]}]</span><span class="footnote-txt">${u[1]}: <i>${u[2]}</i></span></p>`).join("")}</section>`;n.innerHTML+=s}}return U.addFootnotes=nt,U.buildPseudoSpan=Nn,U.configureMarked=ki,U.extractDeclarations=qn,U.getContentForGzhBuiltinTheme=wi,U.getContentForGzhCustomCss=Jr,U.handleFrontMatter=bi,U.modifyCss=et,U.monospace=Pn,U.renderMarkdown=yi,U.replaceCSSVariables=Xr,U.sansSerif=Qr,U.serif=xi,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"}),U})({},hljs,csstree,WenyanMath,macStyleCss,themes,hlThemes);
|
package/dist/core.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { marked as
|
|
1
|
+
import { marked as g } from "marked";
|
|
2
2
|
import { markedHighlight as H } from "marked-highlight";
|
|
3
3
|
import x from "highlight.js";
|
|
4
4
|
import P from "front-matter";
|
|
@@ -7,7 +7,7 @@ import { mathjax as j } from "mathjax-full/js/mathjax.js";
|
|
|
7
7
|
import { TeX as V } from "mathjax-full/js/input/tex.js";
|
|
8
8
|
import { SVG as q } from "mathjax-full/js/output/svg.js";
|
|
9
9
|
import { liteAdaptor as I } from "mathjax-full/js/adaptors/liteAdaptor.js";
|
|
10
|
-
import { RegisterHTMLHandler as
|
|
10
|
+
import { RegisterHTMLHandler as k } from "mathjax-full/js/handlers/html.js";
|
|
11
11
|
import { AllPackages as R } from "mathjax-full/js/input/tex/AllPackages.js";
|
|
12
12
|
import { themes as b } from "./theme.js";
|
|
13
13
|
import { hlThemes as C } from "./hltheme.js";
|
|
@@ -16,19 +16,19 @@ const z = {
|
|
|
16
16
|
displayMath: [["$$", "$$"], ["\\[", "\\]"]],
|
|
17
17
|
processEscapes: !0,
|
|
18
18
|
packages: R
|
|
19
|
-
},
|
|
19
|
+
}, D = {
|
|
20
20
|
fontCache: "none"
|
|
21
21
|
};
|
|
22
22
|
let m;
|
|
23
23
|
if (!m) {
|
|
24
24
|
m = I();
|
|
25
25
|
try {
|
|
26
|
-
|
|
26
|
+
k(m);
|
|
27
27
|
} catch {
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
const
|
|
30
|
+
k(m);
|
|
31
|
+
const E = new V(z), N = new q(D);
|
|
32
32
|
function A(t, i) {
|
|
33
33
|
const l = t.display ? "section" : "span", o = t.display ? "block-equation" : "inline-equation";
|
|
34
34
|
t.typesetRoot = i.adaptor.node(l, { class: o }, [t.typesetRoot]);
|
|
@@ -36,8 +36,8 @@ function A(t, i) {
|
|
|
36
36
|
async function F(t) {
|
|
37
37
|
try {
|
|
38
38
|
const i = j.document(t, {
|
|
39
|
-
InputJax:
|
|
40
|
-
OutputJax:
|
|
39
|
+
InputJax: E,
|
|
40
|
+
OutputJax: N,
|
|
41
41
|
renderActions: {
|
|
42
42
|
addContainer: [190, (o) => {
|
|
43
43
|
for (const r of o.math)
|
|
@@ -64,12 +64,12 @@ function le() {
|
|
|
64
64
|
const t = H({
|
|
65
65
|
emptyLangClass: "hljs",
|
|
66
66
|
langPrefix: "hljs language-",
|
|
67
|
-
highlight: function(r,
|
|
68
|
-
const e = x.getLanguage(
|
|
67
|
+
highlight: function(r, s, a) {
|
|
68
|
+
const e = x.getLanguage(s) ? s : "plaintext";
|
|
69
69
|
return x.highlight(r, { language: e }).value;
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
|
-
|
|
72
|
+
g.use(t);
|
|
73
73
|
const i = {
|
|
74
74
|
name: "attributeImage",
|
|
75
75
|
level: "inline",
|
|
@@ -77,37 +77,37 @@ function le() {
|
|
|
77
77
|
return r.indexOf("![");
|
|
78
78
|
},
|
|
79
79
|
tokenizer(r) {
|
|
80
|
-
const
|
|
81
|
-
if (
|
|
80
|
+
const a = /^!\[([^\]]*)\]\(([^)]+)\)\{(.*?)\}/.exec(r);
|
|
81
|
+
if (a)
|
|
82
82
|
return {
|
|
83
83
|
type: "attributeImage",
|
|
84
|
-
raw:
|
|
85
|
-
alt:
|
|
86
|
-
href:
|
|
87
|
-
attrs:
|
|
84
|
+
raw: a[0],
|
|
85
|
+
alt: a[1],
|
|
86
|
+
href: a[2],
|
|
87
|
+
attrs: a[3]
|
|
88
88
|
};
|
|
89
89
|
},
|
|
90
90
|
renderer(r) {
|
|
91
|
-
const
|
|
92
|
-
([e,
|
|
91
|
+
const s = J(r.attrs), a = Array.from(s).map(
|
|
92
|
+
([e, n]) => /^\d+$/.test(n) ? `${e}:${n}px` : `${e}:${n}`
|
|
93
93
|
).join("; ");
|
|
94
|
-
return `<img src="${r.href}" alt="${r.alt || ""}" title="${r.alt || ""}" style="${
|
|
94
|
+
return `<img src="${r.href}" alt="${r.alt || ""}" title="${r.alt || ""}" style="${a}">`;
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
|
-
|
|
98
|
-
const l =
|
|
97
|
+
g.use({ extensions: [i] });
|
|
98
|
+
const l = g.Renderer, o = g.Parser;
|
|
99
99
|
l.heading = function(r) {
|
|
100
|
-
const
|
|
101
|
-
return `<h${
|
|
100
|
+
const s = o.parseInline(r.tokens), a = r.depth;
|
|
101
|
+
return `<h${a}><span>${s}</span></h${a}>
|
|
102
102
|
`;
|
|
103
103
|
}, l.paragraph = function(r) {
|
|
104
|
-
const
|
|
105
|
-
return
|
|
104
|
+
const s = r.text;
|
|
105
|
+
return s.length > 4 && (/\$\$[\s\S]*?\$\$/g.test(s) || /\\\[[\s\S]*?\\\]/g.test(s)) ? `${s}
|
|
106
106
|
` : `<p>${o.parseInline(r.tokens)}</p>
|
|
107
107
|
`;
|
|
108
|
-
}, l.image = function(r,
|
|
108
|
+
}, l.image = function(r, s, a) {
|
|
109
109
|
return `<img src="${r.href}" alt="${r.text || ""}" title="${r.text || ""}">`;
|
|
110
|
-
},
|
|
110
|
+
}, g.use({ renderer: l });
|
|
111
111
|
}
|
|
112
112
|
function J(t) {
|
|
113
113
|
const i = /* @__PURE__ */ new Map();
|
|
@@ -119,25 +119,25 @@ function J(t) {
|
|
|
119
119
|
function ce(t) {
|
|
120
120
|
const { attributes: i, body: l } = P(t), o = {};
|
|
121
121
|
let r = "";
|
|
122
|
-
const { title:
|
|
123
|
-
return
|
|
122
|
+
const { title: s, description: a, cover: e } = i;
|
|
123
|
+
return s && (o.title = s), a && (r += "> " + a + `
|
|
124
124
|
|
|
125
|
-
`, o.description =
|
|
125
|
+
`, o.description = a), e && (o.cover = e), o.body = r + l, o;
|
|
126
126
|
}
|
|
127
127
|
async function pe(t) {
|
|
128
|
-
const i =
|
|
128
|
+
const i = g.parse(t);
|
|
129
129
|
return await F(i);
|
|
130
130
|
}
|
|
131
131
|
async function fe(t, i, l, o = !0, r = !0) {
|
|
132
|
-
let
|
|
133
|
-
if (i && (
|
|
132
|
+
let s = b.default;
|
|
133
|
+
if (i && (s = b[i], s || (s = Object.values(b).find(
|
|
134
134
|
(c) => c.name.toLowerCase() === i.toLowerCase()
|
|
135
|
-
))), !
|
|
135
|
+
))), !s)
|
|
136
136
|
throw new Error("主题不存在");
|
|
137
137
|
if (!(l in C))
|
|
138
138
|
throw new Error("代码块主题不存在");
|
|
139
|
-
const
|
|
140
|
-
return O(t,
|
|
139
|
+
const a = U(await s.getCss()), n = await C[l].getCss();
|
|
140
|
+
return O(t, a, n, o, r);
|
|
141
141
|
}
|
|
142
142
|
async function O(t, i, l, o = !0, r = !0) {
|
|
143
143
|
r && Y(!1, t), i = W(i, {
|
|
@@ -156,35 +156,35 @@ async function O(t, i, l, o = !0, r = !0) {
|
|
|
156
156
|
}
|
|
157
157
|
]
|
|
158
158
|
});
|
|
159
|
-
const
|
|
159
|
+
const s = f.parse(i, {
|
|
160
160
|
context: "stylesheet",
|
|
161
161
|
positions: !1,
|
|
162
162
|
parseAtrulePrelude: !1,
|
|
163
163
|
parseCustomProperty: !1,
|
|
164
164
|
parseValue: !1
|
|
165
|
-
}),
|
|
165
|
+
}), a = f.parse(l, {
|
|
166
166
|
context: "stylesheet",
|
|
167
167
|
positions: !1,
|
|
168
168
|
parseAtrulePrelude: !1,
|
|
169
169
|
parseCustomProperty: !1,
|
|
170
170
|
parseValue: !1
|
|
171
171
|
});
|
|
172
|
-
if (
|
|
173
|
-
const
|
|
172
|
+
if (s.children.appendList(a.children), o) {
|
|
173
|
+
const n = f.parse(G, {
|
|
174
174
|
context: "stylesheet",
|
|
175
175
|
positions: !1,
|
|
176
176
|
parseAtrulePrelude: !1,
|
|
177
177
|
parseCustomProperty: !1,
|
|
178
178
|
parseValue: !1
|
|
179
179
|
});
|
|
180
|
-
|
|
180
|
+
s.children.appendList(n.children);
|
|
181
181
|
}
|
|
182
|
-
f.walk(
|
|
182
|
+
f.walk(s, {
|
|
183
183
|
visit: "Rule",
|
|
184
|
-
enter(
|
|
185
|
-
const u =
|
|
186
|
-
u && u.forEach((
|
|
187
|
-
const h = f.generate(
|
|
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
188
|
h === "#wenyan" ? $.forEach((y) => {
|
|
189
189
|
const v = f.generate(y.value);
|
|
190
190
|
t.style[y.property] = v;
|
|
@@ -198,56 +198,61 @@ async function O(t, i, l, o = !0, r = !0) {
|
|
|
198
198
|
}
|
|
199
199
|
});
|
|
200
200
|
let e = t.querySelectorAll("mjx-container");
|
|
201
|
-
return e.forEach((
|
|
202
|
-
const c =
|
|
201
|
+
return e.forEach((n) => {
|
|
202
|
+
const c = n.querySelector("svg");
|
|
203
203
|
c.style.width = c.getAttribute("width"), c.style.height = c.getAttribute("height"), c.removeAttribute("width"), c.removeAttribute("height");
|
|
204
|
-
const p =
|
|
205
|
-
|
|
206
|
-
}), e = t.querySelectorAll("pre code"), e.forEach((
|
|
207
|
-
|
|
208
|
-
}), e = t.querySelectorAll("h1, h2, h3, h4, h5, h6, blockquote, pre"), e.forEach((
|
|
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, " "));
|
|
208
|
+
}), e = t.querySelectorAll("h1, h2, h3, h4, h5, h6, blockquote, pre"), e.forEach((n) => {
|
|
209
209
|
const c = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
|
|
210
|
-
f.walk(
|
|
210
|
+
f.walk(s, {
|
|
211
211
|
visit: "Rule",
|
|
212
212
|
enter(u) {
|
|
213
|
-
const
|
|
214
|
-
|
|
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);
|
|
215
215
|
}
|
|
216
|
-
}), c.size > 0 &&
|
|
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);
|
|
217
222
|
}), t.setAttribute("data-provider", "WenYan"), `${t.outerHTML.replace(/class="mjx-solid"/g, 'fill="none" stroke-width="70"')}`;
|
|
218
223
|
}
|
|
219
224
|
function U(t) {
|
|
220
225
|
const i = /--([a-zA-Z0-9\-]+):\s*([^;()]*\((?:[^()]*|\([^()]*\))*\)[^;()]*|[^;]+);/g, l = /var\(--([a-zA-Z0-9\-]+)\)/g, o = {};
|
|
221
226
|
let r;
|
|
222
227
|
for (; (r = i.exec(t)) !== null; ) {
|
|
223
|
-
const e = r[1],
|
|
228
|
+
const e = r[1], n = r[2].trim().replaceAll(`
|
|
224
229
|
`, "");
|
|
225
|
-
o[e] =
|
|
230
|
+
o[e] = n;
|
|
226
231
|
}
|
|
227
232
|
o["sans-serif-font"] || (o["sans-serif-font"] = B), o["monospace-font"] || (o["monospace-font"] = L);
|
|
228
|
-
function
|
|
233
|
+
function s(e, n, c = /* @__PURE__ */ new Set()) {
|
|
229
234
|
if (c.has(e)) return e;
|
|
230
235
|
c.add(e);
|
|
231
236
|
let p = e, u;
|
|
232
237
|
for (; (u = l.exec(p)) !== null; ) {
|
|
233
|
-
const
|
|
234
|
-
if (
|
|
235
|
-
const h = n
|
|
238
|
+
const d = u[1];
|
|
239
|
+
if (n[d]) {
|
|
240
|
+
const h = s(n[d], n, c);
|
|
236
241
|
p = p.replace(u[0], h);
|
|
237
242
|
}
|
|
238
243
|
}
|
|
239
244
|
return p;
|
|
240
245
|
}
|
|
241
246
|
for (const e in o) {
|
|
242
|
-
const
|
|
243
|
-
o[e] =
|
|
247
|
+
const n = s(o[e], o);
|
|
248
|
+
o[e] = n;
|
|
244
249
|
}
|
|
245
|
-
let
|
|
250
|
+
let a = t;
|
|
246
251
|
for (; (r = l.exec(t)) !== null; ) {
|
|
247
252
|
const e = r[1];
|
|
248
|
-
o[e] && (
|
|
253
|
+
o[e] && (a = a.replace(r[0], o[e]));
|
|
249
254
|
}
|
|
250
|
-
return
|
|
255
|
+
return a.replace(/:root\s*\{[^}]*\}/g, "");
|
|
251
256
|
}
|
|
252
257
|
function W(t, i) {
|
|
253
258
|
const l = f.parse(t, {
|
|
@@ -259,19 +264,19 @@ function W(t, i) {
|
|
|
259
264
|
});
|
|
260
265
|
return f.walk(l, {
|
|
261
266
|
visit: "Rule",
|
|
262
|
-
leave: (o, r,
|
|
267
|
+
leave: (o, r, s) => {
|
|
263
268
|
if (o.prelude.type !== "SelectorList") return;
|
|
264
|
-
const
|
|
265
|
-
if (
|
|
266
|
-
const e =
|
|
267
|
-
if (!
|
|
268
|
-
for (const { property: c, value: p, append: u } of
|
|
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)
|
|
269
274
|
if (p) {
|
|
270
|
-
let
|
|
275
|
+
let d = !1;
|
|
271
276
|
f.walk(o.block, (h) => {
|
|
272
|
-
h.type === "Declaration" && h.property === c && (h.value = f.parse(p, { context: "value" }),
|
|
273
|
-
}), !
|
|
274
|
-
|
|
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({
|
|
275
280
|
type: "Declaration",
|
|
276
281
|
property: c,
|
|
277
282
|
value: f.parse(p, { context: "value" })
|
|
@@ -291,46 +296,46 @@ function M(t, i) {
|
|
|
291
296
|
}
|
|
292
297
|
});
|
|
293
298
|
}
|
|
294
|
-
function
|
|
299
|
+
function S(t, i) {
|
|
295
300
|
const l = i.createElement("section");
|
|
296
301
|
t.get("content") && (l.textContent = t.get("content").replace(/['"]/g, ""), t.delete("content"));
|
|
297
|
-
for (const [
|
|
298
|
-
if (
|
|
299
|
-
const e =
|
|
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?[^"'\)]*)(?:"|')?\)/);
|
|
300
305
|
if (e) {
|
|
301
306
|
const p = decodeURIComponent(e[1]);
|
|
302
307
|
l.innerHTML = p;
|
|
303
|
-
} else if (
|
|
304
|
-
const p = atob(
|
|
308
|
+
} else if (n) {
|
|
309
|
+
const p = atob(n[1]);
|
|
305
310
|
l.innerHTML = p;
|
|
306
311
|
} else if (c) {
|
|
307
312
|
const p = i.createElement("img");
|
|
308
313
|
p.src = c[1], p.setAttribute("style", "vertical-align: top;"), l.appendChild(p);
|
|
309
314
|
}
|
|
310
|
-
t.delete(
|
|
315
|
+
t.delete(s);
|
|
311
316
|
}
|
|
312
|
-
const r = Array.from(t.entries()).map(([
|
|
317
|
+
const r = Array.from(t.entries()).map(([s, a]) => `${s}: ${a}`).join("; ");
|
|
313
318
|
return l.style.cssText = r, l;
|
|
314
319
|
}
|
|
315
320
|
function Y(t, i) {
|
|
316
321
|
let l = [], o = 0;
|
|
317
|
-
if (i.querySelectorAll("a[href]").forEach((
|
|
318
|
-
const
|
|
319
|
-
l.push([++o,
|
|
320
|
-
const
|
|
321
|
-
|
|
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);
|
|
322
327
|
}), o > 0)
|
|
323
328
|
if (t) {
|
|
324
|
-
const
|
|
325
|
-
i.innerHTML +=
|
|
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;
|
|
326
331
|
} else {
|
|
327
|
-
const
|
|
328
|
-
i.innerHTML +=
|
|
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;
|
|
329
334
|
}
|
|
330
335
|
}
|
|
331
336
|
export {
|
|
332
337
|
Y as addFootnotes,
|
|
333
|
-
|
|
338
|
+
S as buildPseudoSpan,
|
|
334
339
|
le as configureMarked,
|
|
335
340
|
M as extractDeclarations,
|
|
336
341
|
fe as getContentForGzhBuiltinTheme,
|
package/package.json
CHANGED