From db13a8de67189720aac7e1636b573e06e94edc86 Mon Sep 17 00:00:00 2001 From: Jack Rowlingson Date: Fri, 14 Jun 2019 14:06:17 -0400 Subject: [PATCH] Fix compacting of paragraphs containing self-closing angle bracket components --- addon/utils/compile-markdown.js | 2 +- .../unit/utils/compile-markdown-test.js | 64 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/addon/utils/compile-markdown.js b/addon/utils/compile-markdown.js index a4c442c36..87a34ec0f 100644 --- a/addon/utils/compile-markdown.js +++ b/addon/utils/compile-markdown.js @@ -134,7 +134,7 @@ function compactParagraphs(tokens) { let textWithoutCode = tokenText.replace(/`[\s\S]*?`/g, ''); balance += count(/{{#/g, textWithoutCode); - balance += count(/<[A-Z]/g, textWithoutCode); + balance += count(/<[A-Z]\w*>/g, textWithoutCode); balance -= count(/{{\//g, textWithoutCode); balance -= count(/<\/[A-Z]/g, textWithoutCode); } diff --git a/tests-node/unit/utils/compile-markdown-test.js b/tests-node/unit/utils/compile-markdown-test.js index 0552a2827..4223c3c3c 100644 --- a/tests-node/unit/utils/compile-markdown-test.js +++ b/tests-node/unit/utils/compile-markdown-test.js @@ -20,6 +20,38 @@ describe('Unit | compile-markdown', function(hooks) { assert.equal(result, expected); }); + it('compacting sequential curly bracket paragraphs - non-void angle bracket children', function() { + let input = stripIndent` + {{#foo-bar}}{{/foo-bar}} + + {{#foo-bar}}{{/foo-bar}} + `; + + let result = compileMarkdown(input, { targetHandlebars: true }); + let expected = stripIndent` +

{{#foo-bar}}{{/foo-bar}}

+

{{#foo-bar}}{{/foo-bar}}

+ `; + + assert.equal(result, expected); + }); + + it('compacting sequential curly bracket paragraphs - self-closing angle bracket children', function() { + let input = stripIndent` + {{#foo-bar}}{{/foo-bar}} + + {{#foo-bar}}{{/foo-bar}} + `; + + let result = compileMarkdown(input, { targetHandlebars: true }); + let expected = stripIndent` +

{{#foo-bar}}{{/foo-bar}}

+

{{#foo-bar}}{{/foo-bar}}

+ `; + + assert.equal(result, expected); + }); + it('compacting angle bracket paragraphs', function() { let input = stripIndent` @@ -38,6 +70,38 @@ describe('Unit | compile-markdown', function(hooks) { assert.equal(result, expected); }); + it('compacting sequential angle bracket paragraphs - non-void angle bracket children', function() { + let input = stripIndent` + + + + `; + + let result = compileMarkdown(input, { targetHandlebars: true }); + let expected = stripIndent` +

+

+ `; + + assert.equal(result, expected); + }); + + it('compacting sequential angle bracket paragraphs - self-closing angle bracket children', function() { + let input = stripIndent` + + + + `; + + let result = compileMarkdown(input, { targetHandlebars: true }); + let expected = stripIndent` +

+

+ `; + + assert.equal(result, expected); + }); + it('compacting implicit code blocks', function() { // Surrounding whitespace + 4-space indent = code block in MD let input = stripIndent`