mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 23:40:45 +00:00
* fix: Signal and markdown formatting improvements Markdown IR fixes: - Fix list-paragraph spacing (extra newline between list items and following paragraphs) - Fix nested list indentation and newline handling - Fix blockquote_close emitting redundant newline (inner content handles spacing) - Render horizontal rules as visible ─── separator instead of silent drop - Strip inner cell styles in code-mode tables to prevent overlapping with code_block span Signal formatting fixes: - Normalize URLs for dedup comparison (strip protocol, www., trailing slash) - Render headings as bold text (headingStyle: 'bold') - Add '> ' prefix to blockquotes for visual distinction - Re-chunk after link expansion to respect chunk size limits Tests: - 51 new tests for markdown IR (spacing, lists, blockquotes, tables, HR) - 18 new tests for Signal formatting (URL dedup, headings, blockquotes, HR, chunking) - Update Slack nested list test expectation to match corrected IR output * refactor: style-aware Signal text chunker Replace indexOf-based chunk position tracking with deterministic cursor tracking. The new splitSignalFormattedText: - Splits at whitespace/newline boundaries within the limit - Avoids breaking inside parentheses (preserves expanded link URLs) - Slices style ranges at chunk boundaries with correct local offsets - Tracks position via offset arithmetic instead of fragile indexOf Removes dependency on chunkText from auto-reply/chunk. Tests: 19 new tests covering style preservation across chunk boundaries, edge cases (empty text, under limit, exact split points), and integration with link expansion. * fix: correct Signal style offsets with multiple link expansions applyInsertionsToStyles() was using original coordinates for each insertion without tracking cumulative shift from prior insertions. This caused bold/italic/etc styles to drift to wrong text positions when multiple markdown links expanded in a single message. Added cumulative shift tracking and a regression test. * test: clean up test noise and fix ineffective assertions - Remove console.log from ir.list-spacing and ir.hr-spacing tests - Fix ir.nested-lists.test.ts: remove ineffective regex assertion - Fix ir.hr-spacing.test.ts: add actual assertions to edge case test * refactor: split Signal formatting tests (#9781) (thanks @heyhudson) --------- Co-authored-by: Hudson <258693705+hudson-rivera@users.noreply.github.com> Co-authored-by: Peter Steinberger <steipete@gmail.com>
90 lines
2.7 KiB
TypeScript
90 lines
2.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { markdownToIR } from "./ir.js";
|
|
|
|
describe("markdownToIR tableMode code - style overlap", () => {
|
|
it("should not have overlapping styles when cell has bold text", () => {
|
|
const md = `
|
|
| Name | Value |
|
|
|------|-------|
|
|
| **Bold** | Normal |
|
|
`.trim();
|
|
|
|
const ir = markdownToIR(md, { tableMode: "code" });
|
|
|
|
// Check for overlapping styles
|
|
const codeBlockSpan = ir.styles.find((s) => s.style === "code_block");
|
|
const boldSpan = ir.styles.find((s) => s.style === "bold");
|
|
|
|
// Either:
|
|
// 1. There should be no bold spans in code mode (inner styles stripped), OR
|
|
// 2. If bold spans exist, they should not overlap with code_block span
|
|
if (codeBlockSpan && boldSpan) {
|
|
// Check for overlap
|
|
const overlaps = boldSpan.start < codeBlockSpan.end && boldSpan.end > codeBlockSpan.start;
|
|
// Overlapping styles are the bug - this should fail until fixed
|
|
expect(overlaps).toBe(false);
|
|
}
|
|
});
|
|
|
|
it("should not have overlapping styles when cell has italic text", () => {
|
|
const md = `
|
|
| Name | Value |
|
|
|------|-------|
|
|
| *Italic* | Normal |
|
|
`.trim();
|
|
|
|
const ir = markdownToIR(md, { tableMode: "code" });
|
|
|
|
const codeBlockSpan = ir.styles.find((s) => s.style === "code_block");
|
|
const italicSpan = ir.styles.find((s) => s.style === "italic");
|
|
|
|
if (codeBlockSpan && italicSpan) {
|
|
const overlaps = italicSpan.start < codeBlockSpan.end && italicSpan.end > codeBlockSpan.start;
|
|
expect(overlaps).toBe(false);
|
|
}
|
|
});
|
|
|
|
it("should not have overlapping styles when cell has inline code", () => {
|
|
const md = `
|
|
| Name | Value |
|
|
|------|-------|
|
|
| \`code\` | Normal |
|
|
`.trim();
|
|
|
|
const ir = markdownToIR(md, { tableMode: "code" });
|
|
|
|
const codeBlockSpan = ir.styles.find((s) => s.style === "code_block");
|
|
const codeSpan = ir.styles.find((s) => s.style === "code");
|
|
|
|
if (codeBlockSpan && codeSpan) {
|
|
const overlaps = codeSpan.start < codeBlockSpan.end && codeSpan.end > codeBlockSpan.start;
|
|
expect(overlaps).toBe(false);
|
|
}
|
|
});
|
|
|
|
it("should not have overlapping styles with multiple styled cells", () => {
|
|
const md = `
|
|
| Name | Value |
|
|
|------|-------|
|
|
| **A** | *B* |
|
|
| _C_ | ~~D~~ |
|
|
`.trim();
|
|
|
|
const ir = markdownToIR(md, { tableMode: "code" });
|
|
|
|
const codeBlockSpan = ir.styles.find((s) => s.style === "code_block");
|
|
if (!codeBlockSpan) {
|
|
return;
|
|
}
|
|
|
|
// Check that no non-code_block style overlaps with code_block
|
|
for (const style of ir.styles) {
|
|
if (style.style === "code_block") {
|
|
continue;
|
|
}
|
|
const overlaps = style.start < codeBlockSpan.end && style.end > codeBlockSpan.start;
|
|
expect(overlaps).toBe(false);
|
|
}
|
|
});
|
|
});
|