Skip to content

Commit 900b09b

Browse files
jrowlingsonsamselikoff
authored andcommitted
Fix compacting of paragraphs containing self-closing angle bracket components (ember-learn#384)
1 parent 58d9939 commit 900b09b

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

addon/utils/compile-markdown.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function compactParagraphs(tokens) {
135135

136136
balance += count(/{{#/g, textWithoutCode);
137137
balance += count(/<[A-Z]/g, textWithoutCode);
138+
balance -= count(/[A-Z][^<>]+\/>/g, textWithoutCode);
138139
balance -= count(/{{\//g, textWithoutCode);
139140
balance -= count(/<\/[A-Z]/g, textWithoutCode);
140141
}

tests-node/unit/utils/compile-markdown-test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,38 @@ describe('Unit | compile-markdown', function(hooks) {
2020
assert.equal(result, expected);
2121
});
2222

23+
it('compacting sequential curly bracket paragraphs - non-void angle bracket children', function() {
24+
let input = stripIndent`
25+
{{#foo-bar}}<Foo></Foo>{{/foo-bar}}
26+
27+
{{#foo-bar}}<Foo></Foo>{{/foo-bar}}
28+
`;
29+
30+
let result = compileMarkdown(input, { targetHandlebars: true });
31+
let expected = stripIndent`
32+
<div class="docs-md"><p>{{#foo-bar}}<Foo></Foo>{{/foo-bar}}</p>
33+
<p>{{#foo-bar}}<Foo></Foo>{{/foo-bar}}</p></div>
34+
`;
35+
36+
assert.equal(result, expected);
37+
});
38+
39+
it('compacting sequential curly bracket paragraphs - self-closing angle bracket children', function() {
40+
let input = stripIndent`
41+
{{#foo-bar}}<Foo/>{{/foo-bar}}
42+
43+
{{#foo-bar}}<Foo></Foo>{{/foo-bar}}
44+
`;
45+
46+
let result = compileMarkdown(input, { targetHandlebars: true });
47+
let expected = stripIndent`
48+
<div class="docs-md"><p>{{#foo-bar}}<Foo/>{{/foo-bar}}</p>
49+
<p>{{#foo-bar}}<Foo></Foo>{{/foo-bar}}</p></div>
50+
`;
51+
52+
assert.equal(result, expected);
53+
});
54+
2355
it('compacting angle bracket paragraphs', function() {
2456
let input = stripIndent`
2557
<FooBar>
@@ -38,6 +70,38 @@ describe('Unit | compile-markdown', function(hooks) {
3870
assert.equal(result, expected);
3971
});
4072

73+
it('compacting sequential angle bracket paragraphs - non-void angle bracket children', function() {
74+
let input = stripIndent`
75+
<Baz><Foo></Foo></Baz>
76+
77+
<Baz><Foo></Foo></Baz>
78+
`;
79+
80+
let result = compileMarkdown(input, { targetHandlebars: true });
81+
let expected = stripIndent`
82+
<div class="docs-md"><p><Baz><Foo></Foo></Baz></p>
83+
<p><Baz><Foo></Foo></Baz></p></div>
84+
`;
85+
86+
assert.equal(result, expected);
87+
});
88+
89+
it('compacting sequential angle bracket paragraphs - self-closing angle bracket children', function() {
90+
let input = stripIndent`
91+
<Baz><Foo/></Baz>
92+
93+
<Baz><Foo></Foo></Baz>
94+
`;
95+
96+
let result = compileMarkdown(input, { targetHandlebars: true });
97+
let expected = stripIndent`
98+
<div class="docs-md"><p><Baz><Foo/></Baz></p>
99+
<p><Baz><Foo></Foo></Baz></p></div>
100+
`;
101+
102+
assert.equal(result, expected);
103+
});
104+
41105
it('compacting implicit code blocks', function() {
42106
// Surrounding whitespace + 4-space indent = code block in MD
43107
let input = stripIndent`

0 commit comments

Comments
 (0)