



























@@ -103,4 +103,74 @@ describe("splitMediaFromOutput", () => {
103103{ type: "text", text: "```text\nMEDIA:https://example.com/ignored.png\n```\nAfter" },
104104]);
105105});
106+107+it("extracts markdown image urls while keeping surrounding caption text", () => {
108+expectParsedMediaOutputCase("Caption\n\n", {
109+text: "Caption",
110+mediaUrls: ["https://example.com/chart.png"],
111+});
112+});
113+114+it("keeps inline caption text around markdown images", () => {
115+expectParsedMediaOutputCase("Look  now", {
116+text: "Look now",
117+mediaUrls: ["https://example.com/chart.png"],
118+});
119+});
120+121+it("extracts multiple markdown image urls in order", () => {
122+expectParsedMediaOutputCase(
123+"Before\n\nMiddle\n\nAfter",
124+{
125+text: "Before\nMiddle\nAfter",
126+mediaUrls: ["https://example.com/one.png", "https://example.com/two.png"],
127+},
128+);
129+});
130+131+it("strips markdown image title suffixes from extracted urls", () => {
132+expectParsedMediaOutputCase(
133+'Caption ',
134+{
135+text: "Caption",
136+mediaUrls: ["https://example.com/chart.png"],
137+},
138+);
139+});
140+141+it("keeps balanced parentheses inside markdown image urls", () => {
142+expectParsedMediaOutputCase("Chart .png) now", {
143+text: "Chart now",
144+mediaUrls: ["https://example.com/a_(1).png"],
145+});
146+});
147+148+it.each([
149+"",
150+"",
151+"",
152+] as const)("does not lift local markdown image target: %s", (input) => {
153+expectParsedMediaOutputCase(input, {
154+text: input,
155+mediaUrls: undefined,
156+});
157+});
158+159+it("does not lift markdown image urls that fail media validation", () => {
160+const longUrl = `}.png)`;
161+162+expectParsedMediaOutputCase(longUrl, {
163+text: longUrl,
164+mediaUrls: undefined,
165+});
166+});
167+168+it("leaves very long markdown-image candidate lines as text", () => {
169+const input = `${"prefix ".repeat(3000)}`;
170+171+expectParsedMediaOutputCase(input, {
172+text: input,
173+mediaUrls: undefined,
174+});
175+});
106176});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。