kazzkiq / CodeFlask

A micro code-editor for awesome web pages.
https://kazzkiq.github.io/CodeFlask/
MIT License
1.07k stars 120 forks source link

Prism.util.isActive is not a function #124

Closed d01010101 closed 4 years ago

d01010101 commented 4 years ago

I have a page where I use prism.css and execute prism.js. It does syntax highlighting of a very simple language and it is all fine:

<pre><code class="language-clike">source code goes here</code></pre>

I thought about making this editable. I started with this in the page header:

<script src="codeflask.min.js"></script>

downloaded today from https://unpkg.com/codeflask/build/codeflask.min.js.

It is the only modification, nothing else changed in the page. Yet the syntax highlight within <code> stopped to work properly and the following error shows now in the console:

    Uncaught TypeError: Prism.util.isActive is not a function
    at prism.js:1423
    at Object.run (prism.js:698)
    at insertHighlightedCode (prism.js:542)
    at Object.highlightElement (prism.js:575)
    at Object.highlightAllUnder (prism.js:482)
    at Object.highlightAll (prism.js:451)
    at HTMLDocument.highlightAutomaticallyCallback (prism.js:1100)

The error happens here:

        // only add line numbers if <code> or one of its ancestors has the `line-numbers` class
        if (!Prism.util.isActive(code, PLUGIN_NAME)) {
            return;
        }

where PLUGIN_NAME === "line-numbers". It looks like Prismjs' issue, but why the error does not show without Codeflask?

So, it seems that merely executing codeflask.js causes that Prism.js no more works properly. Why? Should I execute the script in another way? I have only a basic JS knowledge.

I use Prism.js generated with the following options: core, default, clike, line numbers plus some modifications limited to changing keywords and operator regexps, but it seems to work and highlight properly if the Codeflask script is not executed.

d01010101 commented 4 years ago

Can it be an internal inconsistency within Prism.js - plugin incompatibility, which is somewhat triggered by Codeflask?

d01010101 commented 4 years ago

I got it now: I do not need to execute prism.js separately, because it is inside codeflask.js.