Skip to content

[v2] Filter highlightAll: data-* attributes on the script tag are ignored #4128

Description

@DmitrySharabin

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>
  1. Open the page.
  2. In the console, run P.pluginRegistry.peek('filter-highlight-all').plugin.filterKnown.
  3. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions