yzhang-gh / vscode-markdown

Markdown All in One
https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one
MIT License
2.9k stars 322 forks source link

URL is encoded when printing to HTML #1420

Open karlludwinski opened 4 months ago

karlludwinski commented 4 months ago

What's the problem

URLs are encoded when printing to HTML.

What's the expected result

URLs should not be encoded and should output identically to the text representation.

How to reproduce

  1. Create a new .md file with the following text:

https://www.test.com/%test%.html

  1. Run "Markdown All in One: Print current document to HTML."

Result:

The link is output as:

<a href="https://www.test.com/%25test%25.html">https://www.test.com/%test%.html</a>

where % is encoded as %25 in the href attribute.

yzhang-gh commented 4 months ago

This is because this extension follows the VS Code's Markdown settings. You need to disable markdown.preview.linkify.

karlludwinski commented 4 months ago

That does result in a text URL being printed as-is, but if you make it into a link, the same problem occurs. With this in the md file:

[https://www.test.com/%test%.html](https://www.test.com/%test%.html)

and markdown.preview.linkify set to false, the output href is still encoded:

<a href="https://www.test.com/%25test%25.html">https://www.test.com/%test%.html</a>

yzhang-gh commented 4 months ago

This is because VS Code uses markdown-it to convert Markdown to HTML. You can see the same behavior in its online demo.