Remark: Incorrect parsing of HTML comment with trailing text

Created on 16 Jul 2019  路  2Comments  路  Source: remarkjs/remark

Subject of the issue

Parsing an HTML comment that has trailing text includes the text in the HTML node.

Your environment

  • OS: N/A
  • Packages: remark-10.0.1
  • Env: N/A

Steps to reproduce

ast explorer example

markdown snippet:

<!-- some comment --> extra stuff

Expected behaviour

The extra stuff text should be included in its own node, separate from the HTML node.

Actual behaviour

The extra stuff text is included in the HTML node of the comment.

馃憖 areexternal 馃檵 typquestion

Most helpful comment

That being said, the above behavior could be achieved with a plugin.
This guide offers some good pointers on how to get started: https://unified.js.org/create-a-plugin.html

You can also check out the existing plugins to see if anyone else has created a plugin.
https://github.com/remarkjs/remark/blob/master/doc/plugins.md#list-of-plugins

All 2 comments

@chdsbd this is behaving as expected.
remark conforms to the commonmark standard https://commonmark.org

From the commonmark spec

Everything until the next blank line or end of document gets included in the HTML block. So, in the following example, what looks like a Markdown code block is actually part of the HTML block, which continues until a blank line or the end of the document is reached

~~~markdown

int x = 33;

~~~

https://spec.commonmark.org/0.29/#example-131

This is confirmed by the reference parser
https://spec.commonmark.org/dingus/?text=%3C!--%20some%20comment%20--%3E%20extra%20text%0A%0A%0A

Which parses

<!-- some comment --> extra text

as

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document SYSTEM "CommonMark.dtd">
<document xmlns="http://commonmark.org/xml/1.0">
  <html_block>&lt;!-- some comment --&gt; extra text</html_block>
</document>

That being said, the above behavior could be achieved with a plugin.
This guide offers some good pointers on how to get started: https://unified.js.org/create-a-plugin.html

You can also check out the existing plugins to see if anyone else has created a plugin.
https://github.com/remarkjs/remark/blob/master/doc/plugins.md#list-of-plugins

Was this page helpful?
0 / 5 - 0 ratings