@wenyan-md/core 1.0.10 → 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/dist/publish.js +74 -73
- 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/dist/publish.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { JSDOM as
|
|
2
|
-
import { createReadStream as
|
|
3
|
-
import { stat as
|
|
4
|
-
import b, { basename as
|
|
5
|
-
import { FormData as
|
|
6
|
-
var
|
|
1
|
+
import { JSDOM as W } from "jsdom";
|
|
2
|
+
import { createReadStream as L } from "fs";
|
|
3
|
+
import { stat as F } from "fs/promises";
|
|
4
|
+
import b, { basename as N } from "path";
|
|
5
|
+
import { FormData as j, Blob as R } from "formdata-node";
|
|
6
|
+
var I = (t, e, r) => {
|
|
7
7
|
if (!e.has(t))
|
|
8
8
|
throw TypeError("Cannot " + r);
|
|
9
|
-
},
|
|
9
|
+
}, l = (t, e, r) => (I(t, e, "read from private field"), r ? r.call(t) : e.get(t)), p = (t, e, r) => {
|
|
10
10
|
if (e.has(t))
|
|
11
11
|
throw TypeError("Cannot add the same private member more than once");
|
|
12
12
|
e instanceof WeakSet ? e.add(t) : e.set(t, r);
|
|
13
|
-
}, y = (t, e, r, a) => (
|
|
13
|
+
}, y = (t, e, r, a) => (I(t, e, "write to private field"), e.set(t, r), r), P = (t) => typeof t == "object" && t != null && !Array.isArray(t), h = (t) => typeof t == "function", C = (t) => P(t) && h(t[Symbol.asyncIterator]), T = 65536;
|
|
14
14
|
async function* z(t) {
|
|
15
15
|
if (t.byteLength <= T) {
|
|
16
16
|
yield t;
|
|
@@ -22,7 +22,7 @@ async function* z(t) {
|
|
|
22
22
|
e += a.byteLength, yield new Uint8Array(a);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
async function*
|
|
25
|
+
async function* D(t) {
|
|
26
26
|
const e = t.getReader();
|
|
27
27
|
for (; ; ) {
|
|
28
28
|
const { done: r, value: a } = await e.read();
|
|
@@ -35,16 +35,16 @@ async function* x(t) {
|
|
|
35
35
|
for await (const e of t)
|
|
36
36
|
yield* z(e);
|
|
37
37
|
}
|
|
38
|
-
var
|
|
39
|
-
if (
|
|
38
|
+
var H = (t) => {
|
|
39
|
+
if (C(t))
|
|
40
40
|
return x(t);
|
|
41
41
|
if (h(t.getReader))
|
|
42
|
-
return x(
|
|
42
|
+
return x(D(t));
|
|
43
43
|
throw new TypeError(
|
|
44
44
|
"Unsupported data source: Expected either ReadableStream or async iterable."
|
|
45
45
|
);
|
|
46
46
|
};
|
|
47
|
-
async function*
|
|
47
|
+
async function* O(t) {
|
|
48
48
|
let e = 0;
|
|
49
49
|
for (; e !== t.size; ) {
|
|
50
50
|
const a = await t.slice(
|
|
@@ -56,26 +56,26 @@ async function* U(t) {
|
|
|
56
56
|
}
|
|
57
57
|
async function* S(t, e = !1) {
|
|
58
58
|
for (const r of t)
|
|
59
|
-
ArrayBuffer.isView(r) ? e ? yield* z(r) : yield r : h(r.stream) ? yield*
|
|
59
|
+
ArrayBuffer.isView(r) ? e ? yield* z(r) : yield r : h(r.stream) ? yield* H(r.stream()) : yield* O(r);
|
|
60
60
|
}
|
|
61
|
-
function*
|
|
61
|
+
function* U(t, e, r = 0, a) {
|
|
62
62
|
a ??= e;
|
|
63
63
|
let n = r < 0 ? Math.max(e + r, 0) : Math.min(r, e), i = a < 0 ? Math.max(e + a, 0) : Math.min(a, e);
|
|
64
64
|
const s = Math.max(i - n, 0);
|
|
65
65
|
let o = 0;
|
|
66
|
-
for (const
|
|
66
|
+
for (const c of t) {
|
|
67
67
|
if (o >= s)
|
|
68
68
|
break;
|
|
69
|
-
const f = ArrayBuffer.isView(
|
|
69
|
+
const f = ArrayBuffer.isView(c) ? c.byteLength : c.size;
|
|
70
70
|
if (n && f <= n)
|
|
71
71
|
n -= f, i -= f;
|
|
72
72
|
else {
|
|
73
73
|
let d;
|
|
74
|
-
ArrayBuffer.isView(
|
|
74
|
+
ArrayBuffer.isView(c) ? (d = c.subarray(n, Math.min(f, i)), o += d.byteLength) : (d = c.slice(n, Math.min(f, i)), o += d.size), i -= f, n = 0, yield d;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
var u, _, g,
|
|
78
|
+
var u, _, g, V = class v {
|
|
79
79
|
/**
|
|
80
80
|
* Returns a new [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object.
|
|
81
81
|
* The content of the blob consists of the concatenation of the values given in the parameter array.
|
|
@@ -102,7 +102,7 @@ var u, _, g, O = class v {
|
|
|
102
102
|
ArrayBuffer.isView(i) ? s = new Uint8Array(i.buffer.slice(
|
|
103
103
|
i.byteOffset,
|
|
104
104
|
i.byteOffset + i.byteLength
|
|
105
|
-
)) : i instanceof ArrayBuffer ? s = new Uint8Array(i.slice(0)) : i instanceof v ? s = i : s = a.encode(String(i)), y(this, g,
|
|
105
|
+
)) : i instanceof ArrayBuffer ? s = new Uint8Array(i.slice(0)) : i instanceof v ? s = i : s = a.encode(String(i)), y(this, g, l(this, g) + (ArrayBuffer.isView(s) ? s.byteLength : s.size)), l(this, u).push(s);
|
|
106
106
|
}
|
|
107
107
|
const n = r.type === void 0 ? "" : String(r.type);
|
|
108
108
|
y(this, _, /^[\x20-\x7E]*$/.test(n) ? n : "");
|
|
@@ -114,13 +114,13 @@ var u, _, g, O = class v {
|
|
|
114
114
|
* Returns the [`MIME type`](https://developer.mozilla.org/en-US/docs/Glossary/MIME_type) of the [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File).
|
|
115
115
|
*/
|
|
116
116
|
get type() {
|
|
117
|
-
return
|
|
117
|
+
return l(this, _);
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
120
|
* Returns the size of the [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) in bytes.
|
|
121
121
|
*/
|
|
122
122
|
get size() {
|
|
123
|
-
return
|
|
123
|
+
return l(this, g);
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
126
|
* Creates and returns a new [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object which contains data from a subset of the blob on which it's called.
|
|
@@ -130,7 +130,7 @@ var u, _, g, O = class v {
|
|
|
130
130
|
* @param contentType The content type to assign to the new Blob; this will be the value of its type property. The default value is an empty string.
|
|
131
131
|
*/
|
|
132
132
|
slice(e, r, a) {
|
|
133
|
-
return new v(
|
|
133
|
+
return new v(U(l(this, u), this.size, e, r), {
|
|
134
134
|
type: a
|
|
135
135
|
});
|
|
136
136
|
}
|
|
@@ -140,7 +140,7 @@ var u, _, g, O = class v {
|
|
|
140
140
|
async text() {
|
|
141
141
|
const e = new TextDecoder();
|
|
142
142
|
let r = "";
|
|
143
|
-
for await (const a of S(
|
|
143
|
+
for await (const a of S(l(this, u)))
|
|
144
144
|
r += e.decode(a, { stream: !0 });
|
|
145
145
|
return r += e.decode(), r;
|
|
146
146
|
}
|
|
@@ -150,7 +150,7 @@ var u, _, g, O = class v {
|
|
|
150
150
|
async arrayBuffer() {
|
|
151
151
|
const e = new Uint8Array(this.size);
|
|
152
152
|
let r = 0;
|
|
153
|
-
for await (const a of S(
|
|
153
|
+
for await (const a of S(l(this, u)))
|
|
154
154
|
e.set(a, r), r += a.length;
|
|
155
155
|
return e.buffer;
|
|
156
156
|
}
|
|
@@ -158,7 +158,7 @@ var u, _, g, O = class v {
|
|
|
158
158
|
* Returns a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) which upon reading returns the data contained within the [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
|
|
159
159
|
*/
|
|
160
160
|
stream() {
|
|
161
|
-
const e = S(
|
|
161
|
+
const e = S(l(this, u), !0);
|
|
162
162
|
return new ReadableStream({
|
|
163
163
|
async pull(r) {
|
|
164
164
|
const { value: a, done: n } = await e.next();
|
|
@@ -178,7 +178,7 @@ var u, _, g, O = class v {
|
|
|
178
178
|
u = /* @__PURE__ */ new WeakMap();
|
|
179
179
|
_ = /* @__PURE__ */ new WeakMap();
|
|
180
180
|
g = /* @__PURE__ */ new WeakMap();
|
|
181
|
-
var A =
|
|
181
|
+
var A = V;
|
|
182
182
|
Object.defineProperties(A.prototype, {
|
|
183
183
|
type: { enumerable: !0 },
|
|
184
184
|
size: { enumerable: !0 },
|
|
@@ -187,7 +187,7 @@ Object.defineProperties(A.prototype, {
|
|
|
187
187
|
text: { enumerable: !0 },
|
|
188
188
|
arrayBuffer: { enumerable: !0 }
|
|
189
189
|
});
|
|
190
|
-
var k, M,
|
|
190
|
+
var k, M, G = class extends A {
|
|
191
191
|
/**
|
|
192
192
|
* Creates a new File instance.
|
|
193
193
|
*
|
|
@@ -211,7 +211,7 @@ var k, M, V = class extends A {
|
|
|
211
211
|
* Name of the file referenced by the File object.
|
|
212
212
|
*/
|
|
213
213
|
get name() {
|
|
214
|
-
return
|
|
214
|
+
return l(this, k);
|
|
215
215
|
}
|
|
216
216
|
/* c8 ignore next 3 */
|
|
217
217
|
get webkitRelativePath() {
|
|
@@ -221,7 +221,7 @@ var k, M, V = class extends A {
|
|
|
221
221
|
* The last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.
|
|
222
222
|
*/
|
|
223
223
|
get lastModified() {
|
|
224
|
-
return
|
|
224
|
+
return l(this, M);
|
|
225
225
|
}
|
|
226
226
|
get [Symbol.toStringTag]() {
|
|
227
227
|
return "File";
|
|
@@ -231,26 +231,26 @@ k = /* @__PURE__ */ new WeakMap();
|
|
|
231
231
|
M = /* @__PURE__ */ new WeakMap();
|
|
232
232
|
var m, w, J = class q {
|
|
233
233
|
constructor(e) {
|
|
234
|
-
p(this, m, void 0), p(this, w, void 0), y(this, m, e.path), y(this, w, e.start || 0), this.name =
|
|
234
|
+
p(this, m, void 0), p(this, w, void 0), y(this, m, e.path), y(this, w, e.start || 0), this.name = N(l(this, m)), this.size = e.size, this.lastModified = e.lastModified;
|
|
235
235
|
}
|
|
236
236
|
slice(e, r) {
|
|
237
237
|
return new q({
|
|
238
|
-
path:
|
|
238
|
+
path: l(this, m),
|
|
239
239
|
lastModified: this.lastModified,
|
|
240
|
-
start:
|
|
240
|
+
start: l(this, w) + e,
|
|
241
241
|
size: r - e
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
244
|
async *stream() {
|
|
245
|
-
const { mtimeMs: e } = await
|
|
245
|
+
const { mtimeMs: e } = await F(l(this, m));
|
|
246
246
|
if (e > this.lastModified)
|
|
247
247
|
throw new DOMException(
|
|
248
248
|
"The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.",
|
|
249
249
|
"NotReadableError"
|
|
250
250
|
);
|
|
251
|
-
this.size && (yield*
|
|
252
|
-
start:
|
|
253
|
-
end:
|
|
251
|
+
this.size && (yield* L(l(this, m), {
|
|
252
|
+
start: l(this, w),
|
|
253
|
+
end: l(this, w) + this.size - 1
|
|
254
254
|
}));
|
|
255
255
|
}
|
|
256
256
|
get [Symbol.toStringTag]() {
|
|
@@ -259,34 +259,34 @@ var m, w, J = class q {
|
|
|
259
259
|
};
|
|
260
260
|
m = /* @__PURE__ */ new WeakMap();
|
|
261
261
|
w = /* @__PURE__ */ new WeakMap();
|
|
262
|
-
var
|
|
263
|
-
function
|
|
262
|
+
var K = J;
|
|
263
|
+
function X(t, { mtimeMs: e, size: r }, a, n = {}) {
|
|
264
264
|
let i;
|
|
265
|
-
|
|
266
|
-
const s = new
|
|
267
|
-
return i || (i = s.name), new
|
|
265
|
+
P(a) ? [n, i] = [a, void 0] : i = a;
|
|
266
|
+
const s = new K({ path: t, size: r, lastModified: e });
|
|
267
|
+
return i || (i = s.name), new G([s], i, {
|
|
268
268
|
...n,
|
|
269
269
|
lastModified: s.lastModified
|
|
270
270
|
});
|
|
271
271
|
}
|
|
272
|
-
async function
|
|
273
|
-
const a = await
|
|
274
|
-
return
|
|
272
|
+
async function Z(t, e, r) {
|
|
273
|
+
const a = await F(t);
|
|
274
|
+
return X(t, a, e, r);
|
|
275
275
|
}
|
|
276
276
|
/*! Based on fetch-blob. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> & David Frank */
|
|
277
|
-
const
|
|
278
|
-
async function
|
|
279
|
-
const t = await fetch(`${
|
|
277
|
+
const Q = "https://api.weixin.qq.com/cgi-bin/token", Y = "https://api.weixin.qq.com/cgi-bin/draft/add", ee = "https://api.weixin.qq.com/cgi-bin/material/add_material", te = process.env.WECHAT_APP_ID || "", re = process.env.WECHAT_APP_SECRET || "";
|
|
278
|
+
async function ae() {
|
|
279
|
+
const t = await fetch(`${Q}?grant_type=client_credential&appid=${te}&secret=${re}`);
|
|
280
280
|
if (!t.ok) {
|
|
281
281
|
const e = await t.text();
|
|
282
282
|
throw new Error(`获取AccessToken失败: ${t.status} ${e}`);
|
|
283
283
|
}
|
|
284
284
|
return await t.json();
|
|
285
285
|
}
|
|
286
|
-
async function
|
|
287
|
-
const n = new
|
|
286
|
+
async function ie(t, e, r, a) {
|
|
287
|
+
const n = new j();
|
|
288
288
|
n.append("media", e, r);
|
|
289
|
-
const i = await fetch(`${
|
|
289
|
+
const i = await fetch(`${ee}?access_token=${a}&type=${t}`, {
|
|
290
290
|
method: "POST",
|
|
291
291
|
body: n
|
|
292
292
|
});
|
|
@@ -297,8 +297,8 @@ async function ae(t, e, r, a) {
|
|
|
297
297
|
const s = await i.json();
|
|
298
298
|
return s.url && s.url.startsWith("http://") && (s.url = s.url.replace("http://", "https://")), s;
|
|
299
299
|
}
|
|
300
|
-
async function
|
|
301
|
-
const n = await fetch(`${
|
|
300
|
+
async function se(t, e, r, a) {
|
|
301
|
+
const n = await fetch(`${Y}?access_token=${a}`, {
|
|
302
302
|
method: "POST",
|
|
303
303
|
body: JSON.stringify({
|
|
304
304
|
articles: [
|
|
@@ -316,55 +316,56 @@ async function ie(t, e, r, a) {
|
|
|
316
316
|
}
|
|
317
317
|
return await n.json();
|
|
318
318
|
}
|
|
319
|
-
|
|
319
|
+
const B = process.env.HOST_IMAGE_PATH || "", ne = "/mnt/host-downloads";
|
|
320
|
+
async function E(t, e, r) {
|
|
320
321
|
let a, n;
|
|
321
322
|
if (t.startsWith("http")) {
|
|
322
323
|
const s = await fetch(t);
|
|
323
324
|
if (!s.ok || !s.body)
|
|
324
325
|
throw new Error(`Failed to download image from URL: ${t}`);
|
|
325
|
-
const o = b.basename(t.split("?")[0]),
|
|
326
|
-
n = r ?? (
|
|
326
|
+
const o = b.basename(t.split("?")[0]), c = b.extname(o);
|
|
327
|
+
n = r ?? (c === "" ? `${o}.jpg` : o);
|
|
327
328
|
const f = await s.arrayBuffer();
|
|
328
|
-
a = new
|
|
329
|
+
a = new R([f]);
|
|
329
330
|
} else {
|
|
330
|
-
const s = b.basename(
|
|
331
|
-
n = r ?? (
|
|
331
|
+
const s = B ? t.replace(B, ne) : t, o = b.basename(s), c = b.extname(o);
|
|
332
|
+
n = r ?? (c === "" ? `${o}.jpg` : o), a = await Z(t);
|
|
332
333
|
}
|
|
333
|
-
const i = await
|
|
334
|
+
const i = await ie("image", a, n, e);
|
|
334
335
|
if (i.errcode)
|
|
335
336
|
throw new Error(`上传失败,错误码:${i.errcode},错误信息:${i.errmsg}`);
|
|
336
337
|
return i;
|
|
337
338
|
}
|
|
338
|
-
async function
|
|
339
|
+
async function oe(t, e) {
|
|
339
340
|
if (!t.includes("<img"))
|
|
340
341
|
return { html: t, firstImageId: "" };
|
|
341
|
-
const r = new
|
|
342
|
+
const r = new W(t), a = r.window.document, i = Array.from(a.querySelectorAll("img")).map(async (f) => {
|
|
342
343
|
const d = f.getAttribute("src");
|
|
343
344
|
if (d) {
|
|
344
345
|
if (d.startsWith("https://mmbiz.qpic.cn"))
|
|
345
346
|
return d;
|
|
346
347
|
{
|
|
347
|
-
const
|
|
348
|
-
return f.setAttribute("src",
|
|
348
|
+
const $ = await E(d, e);
|
|
349
|
+
return f.setAttribute("src", $.url), $.media_id;
|
|
349
350
|
}
|
|
350
351
|
}
|
|
351
352
|
return null;
|
|
352
353
|
}), o = (await Promise.all(i)).filter(Boolean)[0] || "";
|
|
353
354
|
return { html: r.serialize(), firstImageId: o };
|
|
354
355
|
}
|
|
355
|
-
async function
|
|
356
|
-
const a = await
|
|
356
|
+
async function ue(t, e, r) {
|
|
357
|
+
const a = await ae();
|
|
357
358
|
if (!a.access_token)
|
|
358
359
|
throw a.errcode ? new Error(`获取 Access Token 失败,错误码:${a.errcode},${a.errmsg}`) : new Error(`获取 Access Token 失败: ${a}`);
|
|
359
|
-
const n = e.replace(/\n<li/g, "<li").replace(/<\/li>\n/g, "</li>"), { html: i, firstImageId: s } = await
|
|
360
|
+
const n = e.replace(/\n<li/g, "<li").replace(/<\/li>\n/g, "</li>"), { html: i, firstImageId: s } = await oe(n, a.access_token);
|
|
360
361
|
let o = "";
|
|
361
|
-
if (r ? o = (await
|
|
362
|
+
if (r ? o = (await E(r, a.access_token, "cover.jpg")).media_id : s.startsWith("https://mmbiz.qpic.cn") ? o = (await E(s, a.access_token, "cover.jpg")).media_id : o = s, !o)
|
|
362
363
|
throw new Error("你必须指定一张封面图或者在正文中至少出现一张图片。");
|
|
363
|
-
const
|
|
364
|
-
if (
|
|
365
|
-
return
|
|
366
|
-
throw
|
|
364
|
+
const c = await se(t, i, o, a.access_token);
|
|
365
|
+
if (c.media_id)
|
|
366
|
+
return c;
|
|
367
|
+
throw c.errcode ? new Error(`上传到公众号草稿失败,错误码:${c.errcode},${c.errmsg}`) : new Error(`上传到公众号草稿失败: ${c}`);
|
|
367
368
|
}
|
|
368
369
|
export {
|
|
369
|
-
|
|
370
|
+
ue as publishToDraft
|
|
370
371
|
};
|
package/package.json
CHANGED