Filter highlightAll ignores its data-* attributes in V2: the plugin reads them from document.currentScript, which is null for module scripts.
|
|
|
if (typeof document !== 'undefined') { |
|
const script = document.currentScript; |
|
if (script) { |
|
config.filterKnown = script.hasAttribute('data-filter-known'); |
|
|
|
let attr; |
|
attr = script.getAttribute('data-filter-selector'); |
|
if (attr) { |
|
config.addSelector(attr); |
|
} |
|
attr = script.getAttribute('data-reject-selector'); |
|
if (attr) { |
|
config.reject.addSelector(attr); |
|
} |
|
} |
|
} |
V2 ships the plugin only as an ES module, and dist/prism.js (the one classic-script build) doesn't include it, so no <script> can carry the attributes.
<script type="module" src="https://v2.dev.prismjs.com/dist/index.js"></script>
<script type="module" src="https://v2.dev.prismjs.com/dist/plugins/filter-highlight-all.js" data-filter-known data-reject-selector="code.skip"></script>
<script type="module">
import Prism from "https://v2.dev.prismjs.com/dist/index.js";
window.P = Prism;
</script>
<pre><code class="language-javascript skip">let a = 1;</code></pre>
- Open the page.
- In the console, run
P.pluginRegistry.peek('filter-highlight-all').plugin.filterKnown.
- Inspect the
code.skip block.
Expected: filterKnown is true, and the code.skip block is not highlighted.
Actual: filterKnown is false, and the code.skip block is highlighted (4 tokens).
Prism v2 (v2 @ 719a11f), Chrome
Filter highlightAll ignores its
data-*attributes in V2: the plugin reads them fromdocument.currentScript, which isnullfor module scripts.prism/src/plugins/filter-highlight-all/filter-highlight-all.js
Lines 96 to 112 in 719a11f
V2 ships the plugin only as an ES module, and
dist/prism.js(the one classic-script build) doesn't include it, so no<script>can carry the attributes.P.pluginRegistry.peek('filter-highlight-all').plugin.filterKnown.code.skipblock.Expected:
filterKnownistrue, and thecode.skipblock is not highlighted.Actual:
filterKnownisfalse, and thecode.skipblock is highlighted (4 tokens).Prism v2 (
v2@ 719a11f), Chrome