PrismJS / PrismJS/prism

Autoloader Plugin causes Command Line Plugin to run twice when used from CDN breaking data-filter-* on <pre>

Open
#3,774 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
13k
Forks
1.4k
Avg merge
15h 36m
Merged PRs (30d)
3

Description

Information:

  • Prism version: v1.29.0 via CDN
  • Plugins: Autoloader, Command Line
  • Environment: Browser

Description

This bug occurs when Prism is loaded from a CDN or in a manner similar to a CDN. It does not occur when using a packaged bundle from the website.

When the Autoloader and Command Line plugins are both loaded, the Autoloader plugin causes Prism to scan a document for code boxes twice. When using the Command Line plugin with the data-filter-output="(out)" or the data-filter-continuation="(con)" attribute, the plugin outputs the expected result on the first pass - removing the prefixes and setting the lines to outputs. When Autoloader causes it to run a second time (once the grammar loads, I would assume), there are no longer any prefix on the code block lines, causing the Command Line plugin to think that every line is an input line.

Example

GitLab - contains example .html files and download copy of the Autoloader and Command Line plugins for testing. The files ending in from_git have a copy and pasted version of this file that I used to try and debug what was happening.

JSFiddles (for the .html files in the repo):

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using the linked JSFiddles or the GitLab HTML examples with the Autoloader and Command Line plugins loaded from a CDN. Read the plugin files, especially prism-command-line.js and the Autoloader entry point, and trace both document scans; done means data-filter-output="(out)" and data-filter-continuation="(con)" still produce the expected inputs and outputs after grammar loading.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.