Skip to content

Commit e7087e1

Browse files
miguelcobainsamselikoff
authored andcommitted
do not compact paragraphs when opening component tags are used inside backticks
1 parent 84b8264 commit e7087e1

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

lib/utils/compile-markdown.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ function compactParagraphs(tokens) {
4646
last.text = `${last.text} ${token.text}`;
4747
}
4848

49-
balance += count(/\{\{#/g, token.text);
50-
balance += count(/<[A-Z]/g, token.text);
51-
balance -= count(/\{\{\//g, token.text);
52-
balance -= count(/<\/[A-Z]/g, token.text);
49+
balance += count(/(?<!`.*){{#/g, token.text);
50+
balance += count(/(?<!`.*)<[A-Z]/g, token.text);
51+
balance -= count(/{{\/.*}}(?!.*`)/g, token.text);
52+
balance -= count(/<\/[A-Z][a-z]+>(?!.*`)/g, token.text);
5353
}
5454

5555
return compacted;

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,36 @@ QUnit.module('Unit | compile-markdown', function(hooks) {
8383

8484
assert.equal(result, expected);
8585
});
86+
87+
test('using opening curlies inside backticks shouldn\'t compact paragraphs', function(assert) {
88+
let input = stripIndent`
89+
Foo bar is \`{{#my-component}}\`.
90+
91+
Another paragraph.
92+
`;
93+
94+
let result = compileMarkdown(input, { targetHandlebars: true });
95+
let expected = stripIndent`
96+
<div class="docs-md"><p>Foo bar is <code>&#123;&#123;#my-component&#125;&#125;</code>.</p>
97+
<p>Another paragraph.</p></div>
98+
`;
99+
100+
assert.equal(result, expected);
101+
});
102+
103+
test('using opening angle brackets inside backticks shouldn\'t compact paragraphs', function(assert) {
104+
let input = stripIndent`
105+
Foo bar is \`<My component>\`.
106+
107+
Another paragraph.
108+
`;
109+
110+
let result = compileMarkdown(input, { targetHandlebars: true });
111+
let expected = stripIndent`
112+
<div class="docs-md"><p>Foo bar is <code>&lt;My component&gt;</code>.</p>
113+
<p>Another paragraph.</p></div>
114+
`;
115+
116+
assert.equal(result, expected);
117+
});
86118
});

0 commit comments

Comments
 (0)