From 7c5307b4831c3e0114ab11b7ef4ab31e2e4a75c8 Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Fri, 4 Mar 2022 19:06:30 -0500 Subject: [PATCH 1/2] Fix formatting not being applied after links Signed-off-by: Robin Townsend --- src/Markdown.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Markdown.ts b/src/Markdown.ts index e24c9b72870..9f88fbe41f1 100644 --- a/src/Markdown.ts +++ b/src/Markdown.ts @@ -153,10 +153,27 @@ export default class Markdown { (node.type === 'text' && node.literal === ' ') ) { text = ''; + continue; } + + // Break up text nodes on spaces, so that we don't shoot past them without resetting if (node.type === 'text') { - text += node.literal; + const [thisPart, ...nextParts] = node.literal.split(/( )/); + node.literal = thisPart; + text += thisPart; + + // Add the remaining parts as siblings + nextParts.reverse().forEach(part => { + if (part) { + const nextNode = new commonmark.Node('text'); + nextNode.literal = part; + node.insertAfter(nextNode); + // Make the iterator aware of the newly inserted node + walker.resumeAt(nextNode, true); + } + }); } + // We should not do this if previous node was not a textnode, as we can't combine it then. if ((node.type === 'emph' || node.type === 'strong') && previousNode.type === 'text') { if (event.entering) { From cd5d505aa1817ce73475e2c11f27d16a3b284061 Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Fri, 4 Mar 2022 19:07:40 -0500 Subject: [PATCH 2/2] Test that formatting continues to be applied after links Signed-off-by: Robin Townsend --- test/Markdown-test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/Markdown-test.ts b/test/Markdown-test.ts index d5f38dbb9f9..c1b4b31a298 100644 --- a/test/Markdown-test.ts +++ b/test/Markdown-test.ts @@ -157,5 +157,12 @@ describe("Markdown parser test", () => { const md = new Markdown(testString); expect(md.toHTML()).toEqual(expectedResult); }); + + it('resumes applying formatting to the rest of a message after a link', () => { + const testString = 'http://google.com/_thing_ *does* __not__ exist'; + const expectedResult = 'http://google.com/_thing_ does not exist'; + const md = new Markdown(testString); + expect(md.toHTML()).toEqual(expectedResult); + }); }); });