Skip to content

Commit 3ddf0b9

Browse files
authored
Merge pull request #2972 from mjmlio/fix-2882
fix(mjml-parser): HTML Comments rendered with additional white space … fixes #2882
2 parents 8cb46d5 + 3d87d12 commit 3ddf0b9

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

packages/mjml-parser-xml/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export default function MJMLParser(xml, options = {}, includedIn = []) {
319319
cur.children.push({
320320
line: findLastIndex(lineIndexes, (i) => i <= parser.startIndex) + 1,
321321
tagName: 'mj-raw',
322-
content: `<!-- ${data.trim()} -->`,
322+
content: `<!--${data}-->`,
323323
includedIn,
324324
})
325325
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const chai = require('chai')
2+
const mjml = require('../lib')
3+
4+
const input = `
5+
<mjml>
6+
<mj-body>
7+
<mj-section>
8+
<mj-column>
9+
<mj-text>
10+
<p>View source to see comments below</p>
11+
<!-- comment with standard spaces -->
12+
<br>
13+
<!--comment without spaces-->
14+
<br>
15+
<!-- comment with 5 spaces -->
16+
</mj-text>
17+
</mj-column>
18+
</mj-section>
19+
</mj-body>
20+
</mjml>
21+
`
22+
23+
const { html } = mjml(input)
24+
25+
// should not alter templating syntax, or move the content that is outside any tag (mj-raws)
26+
const expected = [
27+
'<!-- comment with standard spaces -->',
28+
'<!--comment without spaces-->',
29+
'<!-- comment with 5 spaces -->',
30+
]
31+
const indexes = expected.map((str) => html.indexOf(str))
32+
33+
chai.expect(indexes, 'Cmment syntax unaltered').to.not.include(-1)

packages/mjml/test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ require('./lazy-head-style.test')
33
require('./tableWidth.test')
44
require('./wrapper-border-radius.test')
55
require('./accordionTitle-fontWeight.test')
6+
require('./html-comments.test')

0 commit comments

Comments
 (0)