@alexpeng/dsh-custom-plugin 0.9.0 → 0.9.1

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/CHANGELOG.md CHANGED
@@ -4,6 +4,25 @@ All notable changes to this project are documented here. The format loosely
4
4
  follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions
5
5
  follow [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## 0.9.1 — 2026-10-25
8
+
9
+ ### Fixed
10
+
11
+ - **Mermaid 解析失败不再在页面底部留下错误图**:Mermaid 默认会在
12
+ `render()` 抛错前把一个全宽炸弹图追加到 `<body>`(`div#dvx-mmd-*`)并留在
13
+ 那里。现在 `mermaid.initialize` 打开 `suppressErrorRendering`,并在
14
+ `finally` 中清理 `#id` / `#d<id>` / `#i<id>` 三个临时节点;扫描时也会移除
15
+ 旧版本遗留的同名节点。失败代码块按既有设计回退为原始代码,不再出现
16
+ “Syntax error in text / mermaid version …” 卡片。
17
+
18
+ ### Verified
19
+
20
+ - 无头 Edge 复现旧行为(`body > div#dvx-mmd-*` 残留 + “Syntax error in text”),
21
+ 并验证 `suppressErrorRendering` 与 `finally` 清理两条路径都能清除;合法
22
+ flowchart 仍正常渲染。
23
+ - `pnpm check:readme`、`pnpm typecheck`、`pnpm test`(205)、`pnpm build`、
24
+ `pnpm smoke` 全绿。
25
+
7
26
  ## 0.9.0 — 2026-10-25
8
27
 
9
28
  兼容策略改为开放式下限:宿主不再因为 dsh 更新而把插件判为“不支持”。
package/lib/client.js CHANGED
@@ -3118,18 +3118,20 @@ window.__ModuleLoader__.load({
3118
3118
  }
3119
3119
  }
3120
3120
  async function renderMermaid(code, dark = false) {
3121
+ const d = typeof document !== "undefined" ? document : null;
3122
+ const mermaid = (typeof window !== "undefined" ? window : null).mermaid;
3123
+ if (mermaid === void 0) return {
3124
+ ok: false,
3125
+ error: "引擎未就绪"
3126
+ };
3127
+ const id = "vx-mmd-" + Date.now() + Math.floor(Math.random() * 9999);
3121
3128
  try {
3122
- const mermaid = (typeof window !== "undefined" ? window : null).mermaid;
3123
- if (mermaid === void 0) return {
3124
- ok: false,
3125
- error: "引擎未就绪"
3126
- };
3127
3129
  mermaid.initialize({
3128
3130
  startOnLoad: false,
3129
3131
  theme: dark ? "dark" : "default",
3130
- securityLevel: "strict"
3132
+ securityLevel: "strict",
3133
+ suppressErrorRendering: true
3131
3134
  });
3132
- const id = "vx-mmd-" + Date.now() + Math.floor(Math.random() * 9999);
3133
3135
  const out = await mermaid.render(id, code);
3134
3136
  const svg = typeof out === "string" ? out : out?.svg ?? "";
3135
3137
  if (svg === "") return {
@@ -3145,6 +3147,12 @@ window.__ModuleLoader__.load({
3145
3147
  ok: false,
3146
3148
  error: String(error?.message ?? error)
3147
3149
  };
3150
+ } finally {
3151
+ if (d !== null) for (const scratch of [
3152
+ id,
3153
+ "d" + id,
3154
+ "i" + id
3155
+ ]) d.getElementById(scratch)?.remove();
3148
3156
  }
3149
3157
  }
3150
3158
  function extractMermaid(text) {
@@ -3254,6 +3262,7 @@ window.__ModuleLoader__.load({
3254
3262
  async function scanMermaidBlocks(dark) {
3255
3263
  const d = typeof document !== "undefined" ? document : null;
3256
3264
  if (d === null) return;
3265
+ for (const leftover of Array.from(d.querySelectorAll("body > div[id^=\"dvx-mmd-\"]"))) leftover.remove();
3257
3266
  for (const wrap of Array.from(d.querySelectorAll(".vx-mmd-wrap"))) {
3258
3267
  const next = wrap.nextElementSibling;
3259
3268
  if (next === null || !next.classList.contains("md-code-block")) wrap.remove();