Skip to content

Commit

Permalink
fix: import comments cleanup logic (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
kptdobe authored Jan 17, 2024
1 parent b691d4a commit deec675
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/utils/DOMUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ export default class DOMUtils {
// eslint-disable-next-line no-param-reassign
document.body.innerHTML = document.body.innerHTML
// remove html comments
.replace(/<!--(?!>)[\S\s]*?-->/gm, '');
.replace(/><!--(?!>)[\S\s]*?-->/gm, '>')
.replace(/\n<!--(?!>)[\S\s]*?-->/gm, '\n');
}

static removeSpans(document) {
Expand Down
2 changes: 2 additions & 0 deletions test/utils/DOMUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ describe('DOMUtils#removeCommments tests', () => {
test('<p><!-- useless comment \n multiline --></p>', '<p></p>');
test('<p><!-- useless comment \n multiline \n multiline --></p>', '<p></p>');
test('<!-- useless comment --><p>The content stays</p><!-- another useless comment with \n line break -->', '<p>The content stays</p>');
test('<p>This is a paragraph.</p>\n\x3C!--\n<p>Look at this cool image:</p>\n<img border="0" src="pic_trulli.jpg" alt="Trulli">\n-->\n<p>This is a paragraph too.</p>\x3C!-- same line -->\n\x3C!-- single line -->', '<p>This is a paragraph.</p>\n\n<p>This is a paragraph too.</p>\n');
test('<div some-crazy-attribute="" <!--=""><!-- useless comment --></div>', '<div some-crazy-attribute="" <!--=""></div>');
});
});

Expand Down

0 comments on commit deec675

Please sign in to comment.