fix(markdown-core): treat infinity chunk limit as unbounded · openclaw/openclaw@15e4fbf
yhterrance
·
2026-06-14
·
via Recent Commits to openclaw:main
File tree
packages/markdown-core/src
| Original file line number | Diff line number | Diff line change |
|---|
@@ -296,6 +296,16 @@ describe("splitSignalFormattedText", () => {
|
296 | 296 | }); |
297 | 297 | |
298 | 298 | describe("markdownToSignalTextChunks", () => { |
| 299 | +it("treats Infinity as unbounded for media captions", () => { |
| 300 | +const markdown = "Here's **another** photo from today's walk."; |
| 301 | + |
| 302 | +const chunks = markdownToSignalTextChunks(markdown, Number.POSITIVE_INFINITY); |
| 303 | + |
| 304 | +expect(chunks).toHaveLength(1); |
| 305 | +expect(chunks[0]?.text).toBe("Here's another photo from today's walk."); |
| 306 | +expect(chunks[0]?.styles.map((style) => style.style)).toContain("BOLD"); |
| 307 | +}); |
| 308 | + |
299 | 309 | describe("link expansion chunk limit", () => { |
300 | 310 | it("does not exceed chunk limit after link expansion", () => { |
301 | 311 | // Create text that is close to limit, with a link that will expand |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -84,4 +84,18 @@ describe("renderMarkdownIRChunksWithinLimit", () => {
|
84 | 84 | expect(chunks.map((chunk) => chunk.source.text)).toEqual(["a", "b", "c"]); |
85 | 85 | expect(chunks.every((chunk) => chunk.rendered.length <= 1)).toBe(true); |
86 | 86 | }); |
| 87 | + |
| 88 | +it("treats Infinity as no size cap and returns a single chunk", () => { |
| 89 | +const text = "one two three four five six seven eight nine ten"; |
| 90 | +const ir = markdownToIR(text); |
| 91 | +const chunks = renderMarkdownIRChunksWithinLimit({ |
| 92 | + ir, |
| 93 | +limit: Number.POSITIVE_INFINITY, |
| 94 | +renderChunk: renderEscapedHtml, |
| 95 | +measureRendered: (rendered) => rendered.length, |
| 96 | +}); |
| 97 | + |
| 98 | +expect(chunks).toHaveLength(1); |
| 99 | +expect(chunks[0]?.source.text).toBe(text); |
| 100 | +}); |
87 | 101 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -47,6 +47,13 @@ export function renderMarkdownIRChunksWithinLimit<TRendered>(
|
47 | 47 | return []; |
48 | 48 | } |
49 | 49 | |
| 50 | +// Callers pass Infinity to mean "no size cap" (e.g. a media caption that must not be |
| 51 | +// split). resolveIntegerOption rejects non-finite values and would fall back to 1, |
| 52 | +// shattering the text into one chunk per character; emit the whole IR as one chunk. |
| 53 | +if (options.limit === Number.POSITIVE_INFINITY) { |
| 54 | +return [{ source: options.ir, rendered: options.renderChunk(options.ir) }]; |
| 55 | +} |
| 56 | + |
50 | 57 | const normalizedLimit = resolveIntegerOption(options.limit, 1, { min: 1 }); |
51 | 58 | const pending = chunkMarkdownIR(options.ir, normalizedLimit); |
52 | 59 | const finalized: MarkdownIR[] = []; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。