koishi-plugin-latex-render 1.1.1 → 1.1.3

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/index.js CHANGED
@@ -80,7 +80,7 @@ function autoWrapLatex(text) {
80
80
  }
81
81
  const leading = chunk.slice(0, chunk.indexOf(trimmed));
82
82
  const trailing = chunk.slice(chunk.indexOf(trimmed) + trimmed.length);
83
- const mathMatch = trimmed.match(/^([\s::,,。;;]*)(.*?)([\s::,,。;;]*)$/);
83
+ const mathMatch = trimmed.match(/^([\s::,,。;;\*\#`~]*)(.*?)([\s::,,。;;\*\#`~]*)$/);
84
84
  const prefix = mathMatch ? mathMatch[1] : "";
85
85
  const coreMath = mathMatch ? mathMatch[2] : trimmed;
86
86
  const suffix = mathMatch ? mathMatch[3] : "";
@@ -296,10 +296,12 @@ async function renderLatex(ctx, content, config) {
296
296
  try {
297
297
  page = await ctx.puppeteer.page();
298
298
  await page.setContent(html, {
299
- waitUntil: "networkidle0",
299
+ waitUntil: "networkidle2",
300
+ // 修改 1:改成 networkidle2,防止国内 CDN 少量挂起导致超时
300
301
  timeout: 3e4
301
302
  });
302
- await new Promise((resolve) => setTimeout(resolve, 800));
303
+ await page.evaluateHandle("document.fonts.ready");
304
+ await new Promise((resolve) => setTimeout(resolve, 500));
303
305
  const actualHeight = await page.evaluate(() => document.body ? document.body.scrollHeight : 0);
304
306
  const finalHeight = Math.max(actualHeight + 20, height);
305
307
  const buffer = await page.screenshot({
package/lib/index.js CHANGED
@@ -80,7 +80,7 @@ function autoWrapLatex(text) {
80
80
  }
81
81
  const leading = chunk.slice(0, chunk.indexOf(trimmed));
82
82
  const trailing = chunk.slice(chunk.indexOf(trimmed) + trimmed.length);
83
- const mathMatch = trimmed.match(/^([\s::,,。;;]*)(.*?)([\s::,,。;;]*)$/);
83
+ const mathMatch = trimmed.match(/^([\s::,,。;;\*\#`~]*)(.*?)([\s::,,。;;\*\#`~]*)$/);
84
84
  const prefix = mathMatch ? mathMatch[1] : "";
85
85
  const coreMath = mathMatch ? mathMatch[2] : trimmed;
86
86
  const suffix = mathMatch ? mathMatch[3] : "";
@@ -296,10 +296,12 @@ async function renderLatex(ctx, content, config) {
296
296
  try {
297
297
  page = await ctx.puppeteer.page();
298
298
  await page.setContent(html, {
299
- waitUntil: "networkidle0",
299
+ waitUntil: "networkidle2",
300
+ // 修改 1:改成 networkidle2,防止国内 CDN 少量挂起导致超时
300
301
  timeout: 3e4
301
302
  });
302
- await new Promise((resolve) => setTimeout(resolve, 800));
303
+ await page.evaluateHandle("document.fonts.ready");
304
+ await new Promise((resolve) => setTimeout(resolve, 500));
303
305
  const actualHeight = await page.evaluate(() => document.body ? document.body.scrollHeight : 0);
304
306
  const finalHeight = Math.max(actualHeight + 20, height);
305
307
  const buffer = await page.screenshot({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-latex-render",
3
3
  "description": "ChatLuna 专用 - 将 AI 返回的 LaTeX 公式渲染为图片",
4
- "version": "1.1.1",
4
+ "version": "1.1.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [