From 45cf560f4e170600a7c60c66348688400eeee219 Mon Sep 17 00:00:00 2001
From: Shakker
Date: Tue, 12 May 2026 18:44:47 +0100
Subject: [PATCH] test: tighten matrix markdown html basics
---
extensions/matrix/src/matrix/format.test.ts | 52 ++++++++-------------
1 file changed, 20 insertions(+), 32 deletions(-)
diff --git a/extensions/matrix/src/matrix/format.test.ts b/extensions/matrix/src/matrix/format.test.ts
index ab1990a67fb..e4e5a625405 100644
--- a/extensions/matrix/src/matrix/format.test.ts
+++ b/extensions/matrix/src/matrix/format.test.ts
@@ -10,83 +10,71 @@ function createMentionClient(selfUserId = "@bot:example.org") {
describe("markdownToMatrixHtml", () => {
it("renders basic inline formatting", () => {
const html = markdownToMatrixHtml("hi _there_ **boss** `code`");
- expect(html).toContain("there");
- expect(html).toContain("boss");
- expect(html).toContain("code");
+ expect(html).toBe("hi there boss code
");
});
it("renders links as HTML", () => {
const html = markdownToMatrixHtml("see [docs](https://example.com)");
- expect(html).toContain('docs');
+ expect(html).toBe('see docs
');
});
it("does not auto-link bare file references into external urls", () => {
const html = markdownToMatrixHtml("Check README.md and backup.sh");
- expect(html).toContain("README.md");
- expect(html).toContain("backup.sh");
- expect(html).not.toContain('href="http://README.md"');
- expect(html).not.toContain('href="http://backup.sh"');
+ expect(html).toBe("Check README.md and backup.sh
");
});
it("keeps real domains linked even when path segments look like filenames", () => {
const html = markdownToMatrixHtml("See https://docs.example.com/backup.sh");
- expect(html).toContain('href="https://docs.example.com/backup.sh"');
+ expect(html).toBe(
+ 'See https://docs.example.com/backup.sh
',
+ );
});
it("escapes raw HTML", () => {
const html = markdownToMatrixHtml("nope");
- expect(html).toContain("<b>nope</b>");
- expect(html).not.toContain("nope");
+ expect(html).toBe("<b>nope</b>
");
});
it("flattens images into alt text", () => {
const html = markdownToMatrixHtml("");
- expect(html).toContain("alt");
- expect(html).not.toContain("
alt
");
});
it("preserves line breaks", () => {
const html = markdownToMatrixHtml("line1\nline2");
- expect(html).toContain("
line1
\nline2");
});
it("compacts loose ordered lists without paragraph tags", () => {
const html = markdownToMatrixHtml("1. first\n\n2. second\n\n3. third");
- expect(html).toContain("");
- expect(html).toContain("- ");
- expect(html).not.toContain("
");
+ expect(html).toBe("
\n- first
\n- second
\n- third
\n
");
});
it("compacts loose unordered lists without paragraph tags", () => {
const html = markdownToMatrixHtml("- one\n\n- two\n\n- three");
- expect(html).toContain("");
- expect(html).not.toContain("");
+ expect(html).toBe("
");
});
it("keeps tight lists unchanged", () => {
const html = markdownToMatrixHtml("- one\n- two");
- expect(html).toContain("");
- expect(html).not.toContain("");
+ expect(html).toBe("
");
});
it("preserves inline formatting in loose lists", () => {
const html = markdownToMatrixHtml("1. **bold**\n\n2. _italic_");
- expect(html).toContain("bold");
- expect(html).toContain("italic");
- expect(html).not.toContain("");
+ expect(html).toBe("
\n- bold
\n- italic
\n
");
});
it("does not strip paragraph tags outside lists", () => {
const html = markdownToMatrixHtml("Hello\n\nWorld");
- expect(html).toContain("Hello
");
- expect(html).toContain("World
");
+ expect(html).toBe("Hello
\nWorld
");
});
it("compacts nested sublists without paragraph tags", () => {
const html = markdownToMatrixHtml("1. parent\n\n - child\n\n2. other");
- expect(html).toContain("");
- expect(html).toContain("");
- expect(html).not.toContain("");
+ expect(html).toBe(
+ "
\n- parent\n\n
\n- other
\n
",
+ );
});
it("compacts loose lists with mentions via renderMarkdownToMatrixHtmlWithMentions", async () => {
@@ -101,9 +89,9 @@ describe("markdownToMatrixHtml", () => {
it("preserves paragraph wrappers for multi-paragraph list items", () => {
const html = markdownToMatrixHtml("1. First sentence.\n\n Second sentence in the same item.");
- expect(html).toContain("- ");
- expect(html).toContain("
First sentence.
");
- expect(html).toContain("Second sentence in the same item.
");
+ expect(html).toBe(
+ "\n- \n
First sentence.
\nSecond sentence in the same item.
\n \n
",
+ );
});
it("renders qualified Matrix user mentions as matrix.to links and m.mentions metadata", async () => {