Skip to content

Commit

Permalink
Fix HTML multiline comments bug (quantizor#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
eragon512 committed Aug 7, 2019
1 parent ce11e49 commit df83a77
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions index.compiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,21 @@ describe('arbitrary HTML', () => {
Foo
</p>
`);
});

it('throws out multiline HTML comments', () => {
render(compiler(`Foo\n<!-- this is
a
multiline
comment -->`));

expect(root.innerHTML).toMatchInlineSnapshot(`
<p data-reactroot>
Foo
</p>
`);
});

Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import React from 'react';
import unquote from 'unquote';
import stripHtmlComments from 'strip-html-comments';

/** TODO: Drop for React 16? */
const ATTRIBUTE_TO_JSX_PROP_MAP = {
Expand Down Expand Up @@ -1552,7 +1553,7 @@ export function compiler(markdown, options) {
const parser = parserFor(rules);
const emitter = reactFor(ruleOutput(rules));

const jsx = compile(markdown);
const jsx = compile(stripHtmlComments(markdown));

if (footnotes.length) {
jsx.props.children.push(
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
},
"dependencies": {
"prop-types": "^15.6.2",
"strip-html-comments": "^1.0.0",
"unquote": "^1.1.0"
},
"peerDependencies": {
Expand Down

0 comments on commit df83a77

Please sign in to comment.