惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
Y
Y Combinator Blog
博客园_首页
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
阮一峰的网络日志
阮一峰的网络日志
Hugging Face - Blog
Hugging Face - Blog
宝玉的分享
宝玉的分享
B
Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
WordPress大学
WordPress大学
L
LangChain Blog
爱范儿
爱范儿
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
C
Check Point Blog
博客园 - 聂微东
云风的 BLOG
云风的 BLOG
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Help Net Security

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(markdown): a fenced-code line with trailing text is c...
ly-wang19 · 2026-06-27 · via Recent Commits to openclaw:main

File tree

  • packages/markdown-core/src

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,45 @@

1+

// Tests fenced-code-block span scanning used to keep chunk breaks out of code blocks.

2+

import { describe, expect, it } from "vitest";

3+

import { isSafeFenceBreak, parseFenceSpans } from "./fences.js";

4+
5+

describe("parseFenceSpans closing-fence rules", () => {

6+

it("treats a marker line with trailing text as code content, not a closing fence", () => {

7+

// CommonMark: a closing fence may be followed only by whitespace, so "``` not a close" is code

8+

// content and the block stays open until the real closing fence. Reporting an interior offset

9+

// as a safe break would let a chunker split inside the code block.

10+

const text = "```\ncode\n``` not a close\nmore code\n```\n";

11+

const spans = parseFenceSpans(text);

12+
13+

expect(spans).toHaveLength(1);

14+

expect(isSafeFenceBreak(spans, text.indexOf("more code") + 1)).toBe(false);

15+

});

16+
17+

it("does not close on non-space/tab whitespace", () => {

18+

for (const suffix of ["\u00a0", "\v", "\f"]) {

19+

const text = `\`\`\`\ncode\n\`\`\`${suffix}\nmore code\n`;

20+

const spans = parseFenceSpans(text);

21+
22+

expect(spans).toHaveLength(1);

23+

expect(spans[0]?.end).toBe(text.length);

24+

expect(isSafeFenceBreak(spans, text.indexOf("more code") + 1)).toBe(false);

25+

}

26+

});

27+
28+

it("closes fences with CRLF line endings", () => {

29+

const text = "```\r\ncode\r\n```\r\nafter\r\n";

30+

const spans = parseFenceSpans(text);

31+
32+

expect(spans).toHaveLength(1);

33+

expect(isSafeFenceBreak(spans, text.indexOf("after") + 1)).toBe(true);

34+

});

35+
36+

it("still closes on a bare fence, a longer same-marker fence, and keeps an opener info string", () => {

37+

expect(parseFenceSpans("```\ncode\n```\nafter\n")).toHaveLength(1);

38+

expect(parseFenceSpans("```\ncode\n````` \nafter\n")).toHaveLength(1);

39+

expect(parseFenceSpans("```python\nx = 1\n```\n")).toHaveLength(1);

40+
41+

const closed = "```\ncode\n```\nafter\n";

42+

const spans = parseFenceSpans(closed);

43+

expect(isSafeFenceBreak(spans, closed.indexOf("after") + 1)).toBe(true);

44+

});

45+

});

Original file line numberDiff line numberDiff line change

@@ -41,7 +41,7 @@ export function scanFenceSpans(

4141

while (offset <= buffer.length) {

4242

const nextNewline = buffer.indexOf("\n", offset);

4343

const lineEnd = nextNewline === -1 ? buffer.length : nextNewline;

44-

const line = buffer.slice(offset, lineEnd);

44+

const line = buffer.slice(offset, lineEnd).replace(/\r$/, "");

4545
4646

const match = line.match(/^( {0,3})(`{3,}|~{3,})(.*)$/);

4747

if (match && (offset > 0 || startsAtLineStart)) {

@@ -58,9 +58,13 @@ export function scanFenceSpans(

5858

marker,

5959

indent,

6060

};

61-

} else if (open.markerChar === markerChar && markerLen >= open.markerLen) {

62-

// CommonMark allows a closing fence to be longer than the opener, but

63-

// it must use the same marker character to avoid crossing fence kinds.

61+

} else if (

62+

open.markerChar === markerChar &&

63+

markerLen >= open.markerLen &&

64+

/^[ \t]*$/.test(match[3])

65+

) {

66+

// CommonMark permits only spaces or tabs after a closing fence. A marker line carrying

67+

// other trailing text is code content, not a close, so it must not end the block.

6468

const end = lineEnd;

6569

spans.push({

6670

start: open.start,