From e8807cd3dedd2a05195050422e197b745b49ac00 Mon Sep 17 00:00:00 2001 From: Sorunome <mail@sorunome.de> Date: Sat, 22 Dec 2018 14:03:44 +0100 Subject: [PATCH] M->D add heading parsing --- src/matrixmessageprocessor.ts | 8 ++++++++ test/test_matrixmessageprocessor.ts | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/matrixmessageprocessor.ts b/src/matrixmessageprocessor.ts index a0a4c55..1cdeff1 100644 --- a/src/matrixmessageprocessor.ts +++ b/src/matrixmessageprocessor.ts @@ -304,6 +304,14 @@ export class MatrixMessageProcessor { return ""; case "hr": return "\n----------\n"; + case "h1": + case "h2": + case "h3": + case "h4": + case "h5": + case "h6": + const level = parseInt(nodeHtml.tagName[1], 10); + return `**${"#".repeat(level)} ${await this.walkChildNodes(nodeHtml)}**\n`; default: return await this.walkChildNodes(nodeHtml); } diff --git a/test/test_matrixmessageprocessor.ts b/test/test_matrixmessageprocessor.ts index 611496f..af6253c 100644 --- a/test/test_matrixmessageprocessor.ts +++ b/test/test_matrixmessageprocessor.ts @@ -165,6 +165,23 @@ code const result = await mp.FormatMessage(msg, guild as any); expect(result).is.equal("test\n----------\nfoxes"); }); + it("handles headings", async () => { + const mp = new MatrixMessageProcessor(bot); + const guild = new MockGuild("1234"); + const msg = getHtmlMessage(`<h1>fox</h1> +<h2>floof</h2> +<h3>pony</h3> +<h4>hooves</h4> +<h5>tail</h5> +<h6>foxies</h6>`); + const result = await mp.FormatMessage(msg, guild as any); + expect(result).is.equal(`**# fox** +**## floof** +**### pony** +**#### hooves** +**##### tail** +**###### foxies**`); + }); }); describe("FormatMessage / formatted_body / complex", () => { it("html unescapes stuff inside of code", async () => { -- GitLab