Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix formatting not being applied after links (#7990)
Browse files Browse the repository at this point in the history
  • Loading branch information
robintown authored Mar 8, 2022
1 parent 85260ad commit 1f4e286
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions test/Markdown-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_ <em>does</em> <strong>not</strong> exist';
const md = new Markdown(testString);
expect(md.toHTML()).toEqual(expectedResult);
});
});
});

0 comments on commit 1f4e286

Please sign in to comment.