Remark: <a> HTML tag seems not to be handled correctly

Created on 12 Mar 2020  路  5Comments  路  Source: remarkjs/remark

Your environment

  • OS: macOS
  • Packages: remark-parse v7.0.2
  • Env: node and browser

Steps to reproduce

const unified = require('unified');
const md = require('remark-parse');
const parser = unified().use(md);

console.log(parser.parse(`<a href="b">c</a>`).children[0]);

Expected behaviour

The whole <a href="b">c</a> should be parsed as an HTML node

Actual behaviour

{
  type: 'paragraph',
  children: [
    { type: 'html', value: '<a href="b">', position: [Position] },
    { type: 'text', value: 'c', position: [Position] },
    { type: 'html', value: '</a>', position: [Position] }
  ],
  position: Position {
    start: { line: 1, column: 1, offset: 0 },
    end: { line: 1, column: 18, offset: 17 },
    indent: []
  }
}
馃檵 typquestion

All 5 comments

This is expected, because inline HTML can contain Markdown again:

<a href="#">*emphasis works*</a>

emphasis works

@wooorm Get it, thanks for your quick response!

Another thing which made me confused is the result of <a href="b">\nc</a>:

{
  type: 'html',
  value: '<a href="b">\nc</a>',
  position: Position {
    start: { line: 1, column: 1, offset: 0 },
    end: { line: 2, column: 6, offset: 18 },
    indent: [ 1 ]
  }
}

So the markdown in HTML only takes effects when there is no line break?

HTML in Markdown is weird. Because the line has only a complete opening tag, it turns into an HTML block.

<a href="b">
*emphasis doesn鈥檛 work*</a>


emphasis doesn鈥檛 work

I m having the same problem as @pd4d10, with nested HTML tags and HTML tags in the markdown table cells. The styling of the texts are completed messed because it is rendered outside the HTML tags.

Markdown content:*

Something is not right!
<span>Are you sure?</span>
<span>Yes</span>

Rendered output in the browser:

<p>Something is not right!
<span></span>Are you sure?
<span></span><span></span>Yes
</p>

According to this article, markdown should not be allowed in the HTML.

@pd4d10 Please see support.md on how to ask questions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KyleAMathews picture KyleAMathews  路  6Comments

Jolg42 picture Jolg42  路  4Comments

fisker picture fisker  路  4Comments

KyleAMathews picture KyleAMathews  路  6Comments

rauschma picture rauschma  路  4Comments