Skip to content

(html) Code inside <script> tag disappeared #2504

@kkeundotnet

Description

@kkeundotnet

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?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions