markdown-it / markdown-it-container

Fenced container plugin for markdown-it markdown parser
MIT License
496 stars 74 forks source link

With html: true, HTML escaping differ from embedded HTML escaping #11

Closed Lucas-C closed 7 years ago

Lucas-C commented 7 years ago

Hi.

I'm not sure if this is a bug, but this behaviour surprised me.

There are some reproduction steps:

$ cat repro.js
#!/usr/bin/env node
require('fs').readFile(process.argv[2], 'utf8', function (err, input) {
  var md = require('markdown-it')({html: true})
    .use(require('markdown-it-container'), 'container');
  process.stdout.write(md.render(input));
});

$ cat test.md
<div class="embedded-html">
A: "
</div>
<div class="embedded-html">
B: \"
</div>
<div class="embedded-html">
C: \\"
</div>

::: container
A: "
:::
::: container
B: \"
:::
::: container
C: \\"
:::

$ ./repro.js test.md
<div class="embedded-html">
A: "
</div>
<div class="embedded-html">
B: \"
</div>
<div class="embedded-html">
C: \\"
</div>
<div class="container">
<p>A: &quot;</p>
</div>
<div class="container">
<p>B: &quot;</p>
</div>
<div class="container">
<p>C: \&quot;</p>
</div>

It looks like when markdown-it html: true parameter is used, divs generated by markdown-it-container HTML escape their content one more time than div s "simply" embedded as HTML code.

Do you think markdown-it-container could avoid this extra-escaping ? Maybe by detecting if html: true is set ?

puzrin commented 7 years ago

Seems you've missed empty line after first <div>. See spec. That's a very common mistake.

puzrin commented 7 years ago

I don't see double escaping problem. After you add empty line, result should be the same.

If i missed something - add details please.

Lucas-C commented 7 years ago

Got it: http://spec.commonmark.org/0.27/#example-118 Thank you !