


























1+// Canvas-render tests cover [embed] shortcode extraction and text stripping.
2+import { describe, expect, it } from "vitest";
3+import { extractCanvasShortcodes } from "./canvas-render.ts";
4+5+describe("extractCanvasShortcodes", () => {
6+it("does not let a self-closing embed start a greedy block match", () => {
7+// Regression: the block regex used to greedily swallow the span from a
8+// self-closing "[embed ... /]" open tag up to a later stray "[/embed]",
9+// deleting the visible text in between (" keep me ") from channel delivery.
10+const input = '[embed url="https://a.com" /] keep me [/embed]';
11+const { text, previews } = extractCanvasShortcodes(input);
12+13+expect(previews).toHaveLength(1);
14+expect(previews[0]?.url).toBe("https://a.com");
15+// The visible text between the self-closing embed and the stray close
16+// marker must be preserved, not silently stripped.
17+expect(text).toContain("keep me");
18+expect(text).toBe("keep me [/embed]");
19+});
20+21+it("still extracts a normal block embed and strips only the shortcode span", () => {
22+const input = 'before [embed ref="doc1"] hi [/embed] after';
23+const { text, previews } = extractCanvasShortcodes(input);
24+25+expect(previews).toHaveLength(1);
26+expect(previews[0]?.viewId).toBe("doc1");
27+expect(text).toBe("before after");
28+});
29+30+it("still extracts a plain self-closing embed and keeps surrounding text", () => {
31+const input = 'see [embed url="https://b.com" /] end';
32+const { text, previews } = extractCanvasShortcodes(input);
33+34+expect(previews).toHaveLength(1);
35+expect(previews[0]?.url).toBe("https://b.com");
36+expect(text).toBe("see end");
37+});
38+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。