@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 CHANGED
@@ -4,6 +4,11 @@
4
4
 
5
5
  # 文颜 CORE
6
6
 
7
+ [![npm](https://img.shields.io/npm/v/@wenyan-md/core)](https://www.npmjs.com/package/@wenyan-md/core)
8
+ [![License](https://img.shields.io/github/license/caol64/wenyan-core)](LICENSE)
9
+ ![NPM Downloads](https://img.shields.io/npm/dm/%40wenyan-md%2Fcore)
10
+ [![Stars](https://img.shields.io/github/stars/caol64/wenyan-core?style=social)](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,"&nbsp;"))}),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,"&nbsp;"))}),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 d } from "marked";
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 S } from "mathjax-full/js/handlers/html.js";
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
- }, E = {
19
+ }, D = {
20
20
  fontCache: "none"
21
21
  };
22
22
  let m;
23
23
  if (!m) {
24
24
  m = I();
25
25
  try {
26
- S(m);
26
+ k(m);
27
27
  } catch {
28
28
  }
29
29
  }
30
- S(m);
31
- const N = new V(z), D = new q(E);
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: N,
40
- OutputJax: D,
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, n, s) {
68
- const e = x.getLanguage(n) ? n : "plaintext";
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
- d.use(t);
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 s = /^!\[([^\]]*)\]\(([^)]+)\)\{(.*?)\}/.exec(r);
81
- if (s)
80
+ const a = /^!\[([^\]]*)\]\(([^)]+)\)\{(.*?)\}/.exec(r);
81
+ if (a)
82
82
  return {
83
83
  type: "attributeImage",
84
- raw: s[0],
85
- alt: s[1],
86
- href: s[2],
87
- attrs: s[3]
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 n = J(r.attrs), s = Array.from(n).map(
92
- ([e, a]) => /^\d+$/.test(a) ? `${e}:${a}px` : `${e}:${a}`
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="${s}">`;
94
+ return `<img src="${r.href}" alt="${r.alt || ""}" title="${r.alt || ""}" style="${a}">`;
95
95
  }
96
96
  };
97
- d.use({ extensions: [i] });
98
- const l = d.Renderer, o = d.Parser;
97
+ g.use({ extensions: [i] });
98
+ const l = g.Renderer, o = g.Parser;
99
99
  l.heading = function(r) {
100
- const n = o.parseInline(r.tokens), s = r.depth;
101
- return `<h${s}><span>${n}</span></h${s}>
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 n = r.text;
105
- return n.length > 4 && (/\$\$[\s\S]*?\$\$/g.test(n) || /\\\[[\s\S]*?\\\]/g.test(n)) ? `${n}
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, n, s) {
108
+ }, l.image = function(r, s, a) {
109
109
  return `<img src="${r.href}" alt="${r.text || ""}" title="${r.text || ""}">`;
110
- }, d.use({ renderer: l });
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: n, description: s, cover: e } = i;
123
- return n && (o.title = n), s && (r += "> " + s + `
122
+ const { title: s, description: a, cover: e } = i;
123
+ return s && (o.title = s), a && (r += "> " + a + `
124
124
 
125
- `, o.description = s), e && (o.cover = e), o.body = r + l, o;
125
+ `, o.description = a), e && (o.cover = e), o.body = r + l, o;
126
126
  }
127
127
  async function pe(t) {
128
- const i = d.parse(t);
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 n = b.default;
133
- if (i && (n = b[i], n || (n = Object.values(b).find(
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
- ))), !n)
135
+ ))), !s)
136
136
  throw new Error("主题不存在");
137
137
  if (!(l in C))
138
138
  throw new Error("代码块主题不存在");
139
- const s = U(await n.getCss()), a = await C[l].getCss();
140
- return O(t, s, a, o, r);
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 n = f.parse(i, {
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
- }), s = f.parse(l, {
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 (n.children.appendList(s.children), o) {
173
- const a = f.parse(G, {
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
- n.children.appendList(a.children);
180
+ s.children.appendList(n.children);
181
181
  }
182
- f.walk(n, {
182
+ f.walk(s, {
183
183
  visit: "Rule",
184
- enter(a, c, p) {
185
- const u = a.prelude.children;
186
- u && u.forEach((g) => {
187
- const h = f.generate(g), $ = a.block.children.toArray();
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((a) => {
202
- const c = a.querySelector("svg");
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 = a.parentElement;
205
- a.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((a) => {
207
- a.innerHTML = a.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((a) => {
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
209
  const c = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
210
- f.walk(n, {
210
+ f.walk(s, {
211
211
  visit: "Rule",
212
212
  enter(u) {
213
- const g = f.generate(u.prelude), h = a.tagName.toLowerCase();
214
- g.includes(`${h}::after`) ? M(u, c) : g.includes(`${h}::before`) && M(u, p);
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 && a.appendChild(k(c, t.ownerDocument)), p.size > 0 && a.insertBefore(k(p, t.ownerDocument), a.firstChild);
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], a = r[2].trim().replaceAll(`
228
+ const e = r[1], n = r[2].trim().replaceAll(`
224
229
  `, "");
225
- o[e] = a;
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 n(e, a, c = /* @__PURE__ */ new Set()) {
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 g = u[1];
234
- if (a[g]) {
235
- const h = n(a[g], a, c);
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 a = n(o[e], o);
243
- o[e] = a;
247
+ const n = s(o[e], o);
248
+ o[e] = n;
244
249
  }
245
- let s = t;
250
+ let a = t;
246
251
  for (; (r = l.exec(t)) !== null; ) {
247
252
  const e = r[1];
248
- o[e] && (s = s.replace(r[0], o[e]));
253
+ o[e] && (a = a.replace(r[0], o[e]));
249
254
  }
250
- return s.replace(/:root\s*\{[^}]*\}/g, "");
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, n) => {
267
+ leave: (o, r, s) => {
263
268
  if (o.prelude.type !== "SelectorList") return;
264
- const s = o.prelude.children.toArray().map((e) => f.generate(e));
265
- if (s) {
266
- const e = s[0], a = i[e];
267
- if (!a) return;
268
- for (const { property: c, value: p, append: u } of a)
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 g = !1;
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" }), g = !0);
273
- }), !g && u && o.block.children.prepend(
274
- n.createItem({
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 k(t, i) {
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 [n, s] of t)
298
- if (s.includes("url(")) {
299
- const e = s.match(/data:image\/svg\+xml;utf8,(.*<\/svg>)/), a = s.match(/data:image\/svg\+xml;base64,([^"'\)]*)["']?\)/), c = s.match(/(?:"|')?(https?[^"'\)]*)(?:"|')?\)/);
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 (a) {
304
- const p = atob(a[1]);
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(n);
315
+ t.delete(s);
311
316
  }
312
- const r = Array.from(t.entries()).map(([n, s]) => `${n}: ${s}`).join("; ");
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((n) => {
318
- const s = n.textContent || n.innerText, e = n.getAttribute("href");
319
- l.push([++o, s, e]);
320
- const a = i.ownerDocument.createElement("sup");
321
- a.setAttribute("class", "footnote"), a.innerHTML = `[${o}]`, n.after(a);
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 s = `<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>`;
325
- i.innerHTML += s;
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 s = `<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>`;
328
- i.innerHTML += s;
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
- k as buildPseudoSpan,
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 P } from "jsdom";
2
- import { createReadStream as W } from "fs";
3
- import { stat as B } from "fs/promises";
4
- import b, { basename as L } from "path";
5
- import { FormData as N, Blob as j } from "formdata-node";
6
- var F = (t, e, r) => {
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
- }, c = (t, e, r) => (F(t, e, "read from private field"), r ? r.call(t) : e.get(t)), p = (t, e, r) => {
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) => (F(t, e, "write to private field"), e.set(t, r), r), I = (t) => typeof t == "object" && t != null && !Array.isArray(t), h = (t) => typeof t == "function", R = (t) => I(t) && h(t[Symbol.asyncIterator]), T = 65536;
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* C(t) {
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 D = (t) => {
39
- if (R(t))
38
+ var H = (t) => {
39
+ if (C(t))
40
40
  return x(t);
41
41
  if (h(t.getReader))
42
- return x(C(t));
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* U(t) {
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* D(r.stream()) : yield* U(r);
59
+ ArrayBuffer.isView(r) ? e ? yield* z(r) : yield r : h(r.stream) ? yield* H(r.stream()) : yield* O(r);
60
60
  }
61
- function* H(t, e, r = 0, a) {
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 l of t) {
66
+ for (const c of t) {
67
67
  if (o >= s)
68
68
  break;
69
- const f = ArrayBuffer.isView(l) ? l.byteLength : l.size;
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(l) ? (d = l.subarray(n, Math.min(f, i)), o += d.byteLength) : (d = l.slice(n, Math.min(f, i)), o += d.size), i -= f, n = 0, yield d;
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, O = class v {
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, c(this, g) + (ArrayBuffer.isView(s) ? s.byteLength : s.size)), c(this, u).push(s);
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 c(this, _);
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 c(this, g);
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(H(c(this, u), this.size, e, r), {
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(c(this, u)))
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(c(this, u)))
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(c(this, u), !0);
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 = O;
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, V = class extends A {
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 c(this, k);
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 c(this, M);
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 = L(c(this, m)), this.size = e.size, this.lastModified = e.lastModified;
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: c(this, m),
238
+ path: l(this, m),
239
239
  lastModified: this.lastModified,
240
- start: c(this, w) + e,
240
+ start: l(this, w) + e,
241
241
  size: r - e
242
242
  });
243
243
  }
244
244
  async *stream() {
245
- const { mtimeMs: e } = await B(c(this, m));
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* W(c(this, m), {
252
- start: c(this, w),
253
- end: c(this, w) + this.size - 1
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 G = J;
263
- function K(t, { mtimeMs: e, size: r }, a, n = {}) {
262
+ var K = J;
263
+ function X(t, { mtimeMs: e, size: r }, a, n = {}) {
264
264
  let i;
265
- I(a) ? [n, i] = [a, void 0] : i = a;
266
- const s = new G({ path: t, size: r, lastModified: e });
267
- return i || (i = s.name), new V([s], i, {
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 X(t, e, r) {
273
- const a = await B(t);
274
- return K(t, a, e, r);
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 Z = "https://api.weixin.qq.com/cgi-bin/token", Q = "https://api.weixin.qq.com/cgi-bin/draft/add", Y = "https://api.weixin.qq.com/cgi-bin/material/add_material", ee = process.env.WECHAT_APP_ID || "", te = process.env.WECHAT_APP_SECRET || "";
278
- async function re() {
279
- const t = await fetch(`${Z}?grant_type=client_credential&appid=${ee}&secret=${te}`);
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 ae(t, e, r, a) {
287
- const n = new N();
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(`${Y}?access_token=${a}&type=${t}`, {
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 ie(t, e, r, a) {
301
- const n = await fetch(`${Q}?access_token=${a}`, {
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
- async function $(t, e, r) {
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]), l = b.extname(o);
326
- n = r ?? (l === "" ? `${o}.jpg` : o);
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 j([f]);
329
+ a = new R([f]);
329
330
  } else {
330
- const s = b.basename(t), o = b.extname(s);
331
- n = r ?? (o === "" ? `${s}.jpg` : s), a = await X(t);
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 ae("image", a, n, e);
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 se(t, e) {
339
+ async function oe(t, e) {
339
340
  if (!t.includes("<img"))
340
341
  return { html: t, firstImageId: "" };
341
- const r = new P(t), a = r.window.document, i = Array.from(a.querySelectorAll("img")).map(async (f) => {
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 E = await $(d, e);
348
- return f.setAttribute("src", E.url), E.media_id;
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 de(t, e, r) {
356
- const a = await re();
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 se(n, a.access_token);
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 $(r, a.access_token, "cover.jpg")).media_id : s.startsWith("https://mmbiz.qpic.cn") ? o = (await $(s, a.access_token, "cover.jpg")).media_id : o = s, !o)
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 l = await ie(t, i, o, a.access_token);
364
- if (l.media_id)
365
- return l;
366
- throw l.errcode ? new Error(`上传到公众号草稿失败,错误码:${l.errcode},${l.errmsg}`) : new Error(`上传到公众号草稿失败: ${l}`);
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
- de as publishToDraft
370
+ ue as publishToDraft
370
371
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wenyan-md/core",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "Core library for Wenyan markdown rendering & publishing",
5
5
  "author": "Lei <caol64@gmail.com> (https://github.com/caol64)",
6
6
  "license": "Apache-2.0",