Skip to content

Commit

Permalink
Merge pull request #13 from guruhq/sc-122502/add-collapsibles
Browse files Browse the repository at this point in the history
update slackify to include collapsibles and add tests
  • Loading branch information
juliankrispel authored Jan 16, 2024
2 parents 2ed6244 + ba6355f commit 87233c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions slackify-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) + ">";
Expand Down
14 changes: 14 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,19 @@ describe("Slackify HTML", () => {
expect(slackify(input)).toBe(expected);
});
});

it('should handle collapsible elements', () => {

const input = `<details class="ghq-card-content__collapsible" data-ghq-card-content-type="COLLAPSIBLE"><summary class="ghq-card-content__collapsible-summary" data-ghq-card-content-type="COLLAPSIBLE_SUMMARY"><p class="ghq-card-content__paragraph" data-ghq-card-content-type="paragraph">Collapsible Element with nested one</p></summary><div class="ghq-card-content__collapsible-content" data-ghq-card-content-type="COLLAPSIBLE_CONTENT"><p class="ghq-card-content__paragraph" data-ghq-card-content-type="paragraph">Below is nested</p><details class="ghq-card-content__collapsible" data-ghq-card-content-type="COLLAPSIBLE"><summary class="ghq-card-content__collapsible-summary" data-ghq-card-content-type="COLLAPSIBLE_SUMMARY"><p class="ghq-card-content__paragraph" data-ghq-card-content-type="paragraph">Summary</p></summary><div class="ghq-card-content__collapsible-content" data-ghq-card-content-type="COLLAPSIBLE_CONTENT"><p class="ghq-card-content__paragraph" data-ghq-card-content-type="paragraph">Content</p></div></details></div></details>`

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

0 comments on commit 87233c7

Please sign in to comment.