From a042cd043e7d92f9fdabe5b629129341e58e166b Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 5 Nov 2018 10:23:27 -0500 Subject: [PATCH] MM-12880 Properly link the next sibling following a combined text node (#2307) --- app/components/markdown/transform.js | 4 ++ app/components/markdown/transform.test.js | 47 +++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/app/components/markdown/transform.js b/app/components/markdown/transform.js index b8fb6e342..59be2aa70 100644 --- a/app/components/markdown/transform.js +++ b/app/components/markdown/transform.js @@ -37,6 +37,10 @@ export function combineTextNodes(ast) { node._parent._lastChild = node; } } + + // Resume parsing after the current node since otherwise the walker would continue to parse any old text nodes + // that have been merged into this one + walker.resumeAt(node, false); } return ast; diff --git a/app/components/markdown/transform.test.js b/app/components/markdown/transform.test.js index 8eb1f7a6c..5c3d6f2c0 100644 --- a/app/components/markdown/transform.test.js +++ b/app/components/markdown/transform.test.js @@ -172,16 +172,57 @@ describe('Components.Markdown.transform', () => { }], }], }, + }, { + name: 'MM-12880 merging text followed by non-text', + input: 'test: *italics*', + expected: { + type: 'document', + children: [{ + type: 'paragraph', + children: [{ + type: 'text', + literal: 'test: ', + }, { + type: 'emph', + children: [{ + type: 'text', + literal: 'italics', + }], + }], + }], + }, + }, { + name: 'MM-12880 merging text followed by image', + input: 'test: ![image](https://example.com/image)', + expected: { + type: 'document', + children: [{ + type: 'paragraph', + children: [{ + type: 'text', + literal: 'test: ', + }, { + type: 'image', + destination: 'https://example.com/image', + title: '', + children: [{ + type: 'text', + literal: 'image', + }], + }], + }], + }, }]; for (const test of tests) { it(test.name, () => { - const input = makeAst(test.input); + const input = typeof test.input === 'string' ? parser.parse(test.input) : makeAst(test.input); const expected = makeAst(test.expected); const actual = combineTextNodes(input); assert.ok(verifyAst(actual)); - assert.deepStrictEqual(actual, expected); + assert.deepStrictEqual(astToString(actual), astToString(expected)); + assert.deepStrictEqual(stripUnusedFields(actual), stripUnusedFields(expected)); }); } }); @@ -2862,7 +2903,7 @@ function verifyAst(node) { } if (node.next && node.next.prev !== node) { - console.error('node is not linked properly to prev'); + console.error('node is not linked properly to next'); return false; }