wooorm / refractor

Lightweight, robust, elegant virtual syntax highlighting using Prism
MIT License
722 stars 33 forks source link

Markdown rendering strips tags from HTML code blocks #64

Closed codingkoi closed 1 year ago

codingkoi commented 1 year ago

I've run into a problem using refractor 4.8.0 where when a Markdown code block is specified to be html, any tags inside that block get stripped out completely.

A minimal example that reproduces the issue is this snippet of Markdown:

```html
<h1>Some HTML</h1>
```

I set up a Replit example that shows the result of rendering this looks like:

<span class="token code"><span class="token punctuation">```</span><span class="token code-language">html</span>
<span class="token code-block language-html">Some HTML</span>
<span class="token punctuation">```</span></span>

As you can see, the H1 tags are completely gone.

It also only does this if you put the html language on the code block. Without it, the tags aren't stripped out.

Am I using the library wrong? It seems that if I replace the < and > with &lt; and &gt;, that fixes the issue, but if I do that on a full Markdown file, any inlined HTML tags will not be highlighted. It also doesn't seem like that sort of escaping is needed for other file types (e.g. JavaScript).

It looks like this is being caused because of textContent in markdown.js, but I don't know that changing that is the right solution here (or I'd open a PR 😀).

Let me know if you need any more information, or if I can help. Thanks!

wooorm commented 1 year ago

You found a bug! Weird!

codingkoi commented 1 year ago

Awesome! Thanks for the quick turnaround. I'll give it a try and let you know if I have any further issues.

wooorm commented 1 year ago

:)

Released in 4.8.1!