Highlight.js: (html) Code inside <script> tag disappeared

Created on 24 Apr 2020  路  3Comments  路  Source: highlightjs/highlight.js

Describe the issue

When applying highlight.js to the following code block,

<pre><code class="html">&lt;script&gt;foo();&lt;/script&gt;</code></pre>

I am expecting <script>foo();</script>, but it prints <script></script> without foo(); inside. I understand if the javascript cannot be highlighted since the language is set as html. However, the disappearance of the contents does not look good.

Which language seems to have the issue?

html

Are you using highlight or highlightAuto?

I used initHighlightingOnLoad.

...

Sample Code to Reproduce

Here is jsfiddle: https://jsfiddle.net/6ey310qL/1/

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.0.0/styles/default.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.0.0/highlight.min.js"></script>
  </head>
  <body>
    <pre><code class="html">&lt;script&gt;foo();&lt;/script&gt;</code></pre>
    <script>hljs.initHighlightingOnLoad();</script>
  </body>
</html>

I changed:

  • version 10.0.0
  • language as html
  • script source to cloudfare: https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.0.0/highlight.min.js

Expected behavior

<script>foo();</script>

is printed in the code block.

Additional context

Is this a bug? or a feature?

bug help welcome language

All 3 comments

Looks like a bug to me. I'll need to dig in deeper.

v10.0.1 just released includes this fix.

@yyyc514 Thank you very much for fixing this so quickly!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wooorm picture wooorm  路  6Comments

starikovs picture starikovs  路  8Comments

Vad1mo picture Vad1mo  路  7Comments

ghost picture ghost  路  3Comments

vladshcherbin picture vladshcherbin  路  5Comments