Skip to content

Commit

Permalink
Merge pull request #362 from probablyup/remove-unused-rule
Browse files Browse the repository at this point in the history
remove redundant HTML comment removal, do not strip inside code blocks
  • Loading branch information
quantizor authored Jan 9, 2021
1 parent 6f310f0 commit 729f5aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
22 changes: 22 additions & 0 deletions index.compiler.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2830,6 +2830,28 @@ describe('fenced code blocks', () => {
</pre>
`)
})

it('should not strip HTML comments inside fenced blocks', () => {
render(
compiler(
`
\`\`\`html
<!-- something -->
Yeah boi
\`\`\`
`.trim()
)
)

expect(root.innerHTML).toMatchInlineSnapshot(`
<pre>
<code class="lang-html">
&lt;!-- something --&gt;
Yeah boi
</code>
</pre>
`)
})
})

describe('indented code blocks', () => {
Expand Down
14 changes: 5 additions & 9 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ const HTML_BLOCK_ELEMENT_R = /^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?([^>]*)\

const HTML_CHAR_CODE_R = /&([a-z]+);/g

const HTML_COMMENT_R = /^<!--.*?-->/
const HTML_COMMENT_R = /^<!--[\s\S]*?(?:-->)/

/**
* borrowed from React 15(https://github.com/facebook/react/blob/894d20744cba99383ffd847dbd5b6e0800355a5c/src/renderers/dom/shared/HTMLDOMPropertyConfig.js)
Expand Down Expand Up @@ -837,9 +837,9 @@ function parseBlock(parse, content, state): MarkdownToJSX.ParserResult {
return parse(content + '\n\n', state)
}

const parseCaptureInline: MarkdownToJSX.Parser<ReturnType<
typeof parseInline
>> = (capture, parse, state) => {
const parseCaptureInline: MarkdownToJSX.Parser<
ReturnType<typeof parseInline>
> = (capture, parse, state) => {
return {
content: parseInline(parse, capture[1], state),
}
Expand Down Expand Up @@ -1032,10 +1032,6 @@ export function compiler(
: undefined
}

function stripHtmlComments(html) {
return html.replace(/<!--[\s\S]*?(?:-->)/g, '')
}

/* istanbul ignore next */
if (process.env.NODE_ENV !== 'production') {
if (typeof markdown !== 'string') {
Expand Down Expand Up @@ -1797,7 +1793,7 @@ export function compiler(
const parser = parserFor(rules)
const emitter: Function = reactFor(ruleOutput(rules))

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

if (footnotes.length) {
jsx.props.children.push(
Expand Down

0 comments on commit 729f5aa

Please sign in to comment.