From ba6355ff39f3845edc25f7cda86071fde8535c8e Mon Sep 17 00:00:00 2001 From: Julian Krispel-Samsel Date: Fri, 12 Jan 2024 13:19:44 +0000 Subject: [PATCH] update slackify to include collapsibles and add tests --- slackify-html.js | 5 +++++ test.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/slackify-html.js b/slackify-html.js index 9e35b1a..9bc44b9 100644 --- a/slackify-html.js +++ b/slackify-html.js @@ -245,6 +245,11 @@ function walk(dom, nesting) { let innerOutput; switch (el.name) { + case "summary": + out += `\n*${walk(el.children).trim()}*\n` + break; + + case "a": if (el.attribs && el.attribs.href) { out += "<" + el.attribs.href + "|" + walkLink(el.children) + ">"; diff --git a/test.js b/test.js index 0f78bed..12b04c8 100644 --- a/test.js +++ b/test.js @@ -293,5 +293,19 @@ describe("Slackify HTML", () => { expect(slackify(input)).toBe(expected); }); }); + + it('should handle collapsible elements', () => { + + const input = `

Collapsible Element with nested one

Below is nested

Summary

Content

` + + const expected = ` +*Collapsible Element with nested one* +Below is nested + +*Summary* +Content +` + expect(slackify(input)).toBe(expected); + }) }); });