Skip to content

Commit 6370e8e

Browse files
authored
Merge pull request #194 from ember-learn/bugfix/markdown-compiler-angle-bracket
[bugfix] Prevents all Marked escaping in plain text
2 parents d6d5555 + 622d03a commit 6370e8e

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

lib/utils/compile-markdown.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ class HBSRenderer extends marked.Renderer {
7474
return code.replace(/^<pre>/, '<pre class="docs-md__code">');
7575
}
7676

77-
// Unescape quotes in text, as they may be part of a Handlebars statement
77+
// Unescape markdown escaping in general, since it can interfere with
78+
// Handlebars templating
7879
text() {
7980
let text = super.text.apply(this, arguments);
8081
if (this.config.targetHandlebars) {
8182
text = text
82-
.replace(/&quot;|&#34;/g, `"`)
83-
.replace(/&apos;|&#39;/g, `'`);
83+
.replace(/&amp;/g, '&')
84+
.replace(/&lt;/g, '<')
85+
.replace(/&gt;/g, '>')
86+
.replace(/&quot;|&#34;/g, '"')
87+
.replace(/&apos;|&#39;/g, '\'');
8488
}
8589
return text;
8690
}

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

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

3838
assert.equal(result, expected);
3939
});
40+
41+
test('classic components remain unescaped', function(assert) {
42+
let input = stripIndent`
43+
{{#foo-bar prop="value" otherProp='value'}}
44+
45+
{{/foo-bar}}
46+
`;
47+
48+
let result = compileMarkdown(input, { targetHandlebars: true });
49+
let expected = stripIndent`
50+
<div class="docs-md"><p>{{#foo-bar prop="value" otherProp='value'}} {{/foo-bar}}</p></div>
51+
`;
52+
53+
assert.equal(result, expected);
54+
});
55+
56+
test('angle bracket contextual components remain unescaped', function(assert) {
57+
let input = stripIndent`
58+
<foo.bar @prop={{value}}></foo.bar>
59+
`;
60+
61+
let result = compileMarkdown(input, { targetHandlebars: true });
62+
let expected = stripIndent`
63+
<div class="docs-md"><p><foo.bar @prop={{value}}></foo.bar></p></div>
64+
`;
65+
66+
assert.equal(result, expected);
67+
});
4068
});

0 commit comments

Comments
 (0)