Skip to content

Commit

Permalink
Fix compacting of paragraphs containing self-closing angle bracket co…
Browse files Browse the repository at this point in the history
…mponents
  • Loading branch information
jrowlingson committed Jun 14, 2019
1 parent 296f4a9 commit db13a8d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addon/utils/compile-markdown.js
Expand Up @@ -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);
}
Expand Down
64 changes: 64 additions & 0 deletions tests-node/unit/utils/compile-markdown-test.js
Expand Up @@ -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></Foo>{{/foo-bar}}
{{#foo-bar}}<Foo></Foo>{{/foo-bar}}
`;

let result = compileMarkdown(input, { targetHandlebars: true });
let expected = stripIndent`
<div class="docs-md"><p>{{#foo-bar}}<Foo></Foo>{{/foo-bar}}</p>
<p>{{#foo-bar}}<Foo></Foo>{{/foo-bar}}</p></div>
`;

assert.equal(result, expected);
});

it('compacting sequential curly bracket paragraphs - self-closing angle bracket children', function() {
let input = stripIndent`
{{#foo-bar}}<Foo/>{{/foo-bar}}
{{#foo-bar}}<Foo></Foo>{{/foo-bar}}
`;

let result = compileMarkdown(input, { targetHandlebars: true });
let expected = stripIndent`
<div class="docs-md"><p>{{#foo-bar}}<Foo/>{{/foo-bar}}</p>
<p>{{#foo-bar}}<Foo></Foo>{{/foo-bar}}</p></div>
`;

assert.equal(result, expected);
});

it('compacting angle bracket paragraphs', function() {
let input = stripIndent`
<FooBar>
Expand All @@ -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`
<Baz><Foo></Foo></Baz>
<Baz><Foo></Foo></Baz>
`;

let result = compileMarkdown(input, { targetHandlebars: true });
let expected = stripIndent`
<div class="docs-md"><p><Baz><Foo></Foo></Baz></p>
<p><Baz><Foo></Foo></Baz></p></div>
`;

assert.equal(result, expected);
});

it('compacting sequential angle bracket paragraphs - self-closing angle bracket children', function() {
let input = stripIndent`
<Baz><Foo/></Baz>
<Baz><Foo></Foo></Baz>
`;

let result = compileMarkdown(input, { targetHandlebars: true });
let expected = stripIndent`
<div class="docs-md"><p><Baz><Foo/></Baz></p>
<p><Baz><Foo></Foo></Baz></p></div>
`;

assert.equal(result, expected);
});

it('compacting implicit code blocks', function() {
// Surrounding whitespace + 4-space indent = code block in MD
let input = stripIndent`
Expand Down

0 comments on commit db13a8d

Please sign in to comment.