Fix atom.ui.markdown issue with rendering of HTML in code blocks

This commit is contained in:
Andrew Dupont 2024-04-21 11:36:06 -07:00
parent 62a35bccad
commit 18e0da8baa
2 changed files with 23 additions and 2 deletions

View File

@ -1,3 +1,4 @@
const dedent = require('dedent');
describe("Renders Markdown", () => {
describe("properly when given no opts", () => {
@ -7,6 +8,26 @@ describe("Renders Markdown", () => {
});
});
it(`escapes HTML in code blocks properly`, () => {
let input = dedent`
Lorem ipsum dolor.
\`\`\`html
<p>sit amet</p>
\`\`\`
`
let expected = dedent`
<p>Lorem ipsum dolor.</p>
<pre><code class="language-html">&lt;p&gt;sit amet&lt;/p&gt;
</code></pre>
`
expect(
atom.ui.markdown.render(input).trim()
).toBe(expected);
})
describe("transforms links correctly", () => {
it("makes no changes to a fqdn link", () => {
expect(atom.ui.markdown.render("[Hello World](https://github.com)"))

View File

@ -249,8 +249,8 @@ function renderMarkdown(content, givenOpts = {}) {
// Here we can add some simple additions that make code highlighting possible later on,
// but doesn't actually preform any code highlighting.
md.options.highlight = function(str, lang) {
return `<pre><code class="language-${lang}">${str}</code></pre>`;
md.options.highlight = function (str, lang) {
return `<pre><code class="language-${lang}">${md.utils.escapeHtml(str)}</code></pre>`;
};
// Process disables