From 3eb55eb01fa2c8a2ea12e8d7e645651ed2f301bd Mon Sep 17 00:00:00 2001 From: Julian Krispel-Samsel Date: Fri, 8 Jul 2022 13:17:45 +0100 Subject: [PATCH] accomodate nodes inside table elements, add test case --- slackify-html.js | 4 ++-- tests.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/slackify-html.js b/slackify-html.js index 93b8152..4e80550 100644 --- a/slackify-html.js +++ b/slackify-html.js @@ -115,10 +115,10 @@ function walkTableBody(dom) { out += el.data; } else if ('td' === el.name) { - out += '| ' + walk(el.children) + ' '; + out += "| " + walk(el.children, 0, true) + " "; } else if ('tr' === el.name) { - out += walkTableBody(el.children) + '|\n'; + out += walkTableBody(el.children).replace(/\n/gi, " ") + "|\n"; } }); } diff --git a/tests.js b/tests.js index 504fc38..c011603 100644 --- a/tests.js +++ b/tests.js @@ -147,8 +147,21 @@ tap.test('full example', function vcheck(t) { `; var expected = '*Security Overview Header*\n\n*We take the security of your data very seriously!*\n\nIn order to instill the necessary confidence, we wanted to provide full transparency on _why_, _who_, _where_, _when_ and _how_ we protect your data.\n\nGiven the sensitive nature of your content and need to maintain your privacy being a priority for us, we wanted to share the practices and policies we have put into place.\n\n\n>Here\'s a test blockquote *with bolded* information\n\nRemember this list\n\n1. foo\n2. bar\n3. buz\n\nand this list too...\n\n• _abc_\n • sub 1\n • sub 2\n\n\n• *def*\n• xyz\n\n\`and this\`\n\n\`\`\`\nblah\n\n\n\`\`\`\n\n\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Foo | Bar | Baz |\n| abc | def | ghi |\n\n'; -var output = slackify(input); + var output = slackify(input); t.equals(output, expected); t.end(); }); + + + +tap.test("tables with paragraph", function vcheck(t) { + var input = '

one

dwqtwo

three

dwqdwq

dwqdwqdwq

dwqdwqdwqdwq

' + var expected = `| one | dwqtwo | three | +| dwqdwq | dwqdwqdwq | dwqdwqdwqdwq | +`; + + var output = slackify(input); + t.equal(output, expected); + t.end(); +});