Clean up markdown of HTML entities too

Closes #3006
This commit is contained in:
Kalle
2026-04-26 10:24:34 +03:00
parent 23d2cda288
commit ae6401f429
2 changed files with 58 additions and 1 deletions

View File

@@ -1,5 +1,9 @@
import { describe, expect, test } from "vitest";
import { pathnameFromPotentialURL, truncateBySentence } from "./strings";
import {
pathnameFromPotentialURL,
removeMarkdown,
truncateBySentence,
} from "./strings";
describe("pathnameFromPotentialURL()", () => {
test("Resolves path name from valid URL", () => {
@@ -44,3 +48,30 @@ describe("truncateBySentence()", () => {
expect(truncateBySentence(text, 20)).toBe("First line");
});
});
describe("removeMarkdown()", () => {
test("Decodes   entities and collapses runs", () => {
const text = "     Global Gauntlet is an event";
expect(removeMarkdown(text)).toBe("Global Gauntlet is an event");
});
test("Decodes common named HTML entities", () => {
expect(removeMarkdown("Tom & Jerry <3 "hi"")).toBe(
'Tom & Jerry <3 "hi"',
);
});
test("Decodes numeric HTML entities", () => {
expect(removeMarkdown("caf&#233; &#x26; tea")).toBe("café & tea");
});
test("Leaves unknown named entities untouched", () => {
expect(removeMarkdown("AT&amp;T &fakeentity; rules")).toBe(
"AT&T &fakeentity; rules",
);
});
test("Strips HTML tags and markdown emphasis", () => {
expect(removeMarkdown("<p>Hello **world**!</p>")).toBe("Hello world!");
});
});