Nathan_James
Nathan_James

Reputation: 159

HighlightJS not highlighting certain code fragments

I'm using HighlightJS to format code that's being stored in a model's TextField of my Django application.

Here is the template HTML:

<pre>
  <code class="{{ compiler.highlight_js_alias }}">{{ compiler.unit_test_boilerplate_code }}</code>
</pre>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/styles/default.min.css"
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js"></script>
<script>hljs.highlightAll();</script>

Example output:

<pre>        
  <code class="ruby hljs language-ruby">
    <span class="hljs-keyword">class</span> 
    <span class="hljs-title class_">Person</span>
    :
    <span class="hljs-keyword">def</span> 
    <span class="hljs-title function_">__init__</span>
    (
    <span class="hljs-params">
    <span class="hljs-variable language_">self</span>, name, age</span>
    ):
    <span class="hljs-variable language_">self</span>
    .name = name
    <span class="hljs-variable language_">self</span>
    .age = age
    me = Person(
    <span class="hljs-string">"Nathan"</span>
    <span class="hljs-number">32</span>
    )
    print(me.name)
  </code>
</pre>

Why are certain fragments not highlighted? Thank you for any advice.

Upvotes: 1

Views: 1364

Answers (1)

Nathan_James
Nathan_James

Reputation: 159

After inspecting the outputted HTML of HighlightJS' own demos, it seems this is expected behavior.

Upvotes: 1

Related Questions