mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:08:26 +00:00
fix: add per-channel markdown table conversion (#1495) (thanks @odysseus0)
This commit is contained in:
@@ -11,7 +11,7 @@ describe("markdownToIR tableMode bullets", () => {
|
||||
`.trim();
|
||||
|
||||
const ir = markdownToIR(md, { tableMode: "bullets" });
|
||||
|
||||
|
||||
// Should contain bullet points with header:value format
|
||||
expect(ir.text).toContain("• Value: 1");
|
||||
expect(ir.text).toContain("• Value: 2");
|
||||
@@ -29,7 +29,7 @@ describe("markdownToIR tableMode bullets", () => {
|
||||
`.trim();
|
||||
|
||||
const ir = markdownToIR(md, { tableMode: "bullets" });
|
||||
|
||||
|
||||
// First column becomes row label
|
||||
expect(ir.text).toContain("Speed");
|
||||
expect(ir.text).toContain("Scale");
|
||||
@@ -40,22 +40,20 @@ describe("markdownToIR tableMode bullets", () => {
|
||||
expect(ir.text).toContain("• Postgres: Large");
|
||||
});
|
||||
|
||||
it("preserves flat mode as default", () => {
|
||||
it("leaves table syntax untouched by default", () => {
|
||||
const md = `
|
||||
| A | B |
|
||||
|---|---|
|
||||
| 1 | 2 |
|
||||
`.trim();
|
||||
|
||||
const ir = markdownToIR(md); // default is flat
|
||||
|
||||
// Flat mode uses tabs
|
||||
expect(ir.text).toContain("A");
|
||||
expect(ir.text).toContain("B");
|
||||
expect(ir.text).toContain("1");
|
||||
expect(ir.text).toContain("2");
|
||||
// Should not have bullet formatting
|
||||
const ir = markdownToIR(md);
|
||||
|
||||
// No table conversion by default
|
||||
expect(ir.text).toContain("| A | B |");
|
||||
expect(ir.text).toContain("| 1 | 2 |");
|
||||
expect(ir.text).not.toContain("•");
|
||||
expect(ir.styles.some((style) => style.style === "code_block")).toBe(false);
|
||||
});
|
||||
|
||||
it("handles empty cells gracefully", () => {
|
||||
@@ -67,7 +65,7 @@ describe("markdownToIR tableMode bullets", () => {
|
||||
`.trim();
|
||||
|
||||
const ir = markdownToIR(md, { tableMode: "bullets" });
|
||||
|
||||
|
||||
// Should handle empty cell without crashing
|
||||
expect(ir.text).toContain("B");
|
||||
expect(ir.text).toContain("• Value: 2");
|
||||
@@ -81,11 +79,41 @@ describe("markdownToIR tableMode bullets", () => {
|
||||
`.trim();
|
||||
|
||||
const ir = markdownToIR(md, { tableMode: "bullets" });
|
||||
|
||||
|
||||
// Should have bold style for row label
|
||||
const hasRowLabelBold = ir.styles.some(
|
||||
(s) => s.style === "bold" && ir.text.slice(s.start, s.end) === "Row1"
|
||||
(s) => s.style === "bold" && ir.text.slice(s.start, s.end) === "Row1",
|
||||
);
|
||||
expect(hasRowLabelBold).toBe(true);
|
||||
});
|
||||
|
||||
it("renders tables as code blocks in code mode", () => {
|
||||
const md = `
|
||||
| A | B |
|
||||
|---|---|
|
||||
| 1 | 2 |
|
||||
`.trim();
|
||||
|
||||
const ir = markdownToIR(md, { tableMode: "code" });
|
||||
|
||||
expect(ir.text).toContain("| A | B |");
|
||||
expect(ir.text).toContain("| 1 | 2 |");
|
||||
expect(ir.styles.some((style) => style.style === "code_block")).toBe(true);
|
||||
});
|
||||
|
||||
it("preserves inline styles and links in bullets mode", () => {
|
||||
const md = `
|
||||
| Name | Value |
|
||||
|------|-------|
|
||||
| _Row_ | [Link](https://example.com) |
|
||||
`.trim();
|
||||
|
||||
const ir = markdownToIR(md, { tableMode: "bullets" });
|
||||
|
||||
const hasItalic = ir.styles.some(
|
||||
(s) => s.style === "italic" && ir.text.slice(s.start, s.end) === "Row",
|
||||
);
|
||||
expect(hasItalic).toBe(true);
|
||||
expect(ir.links.some((link) => link.href === "https://example.com")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user