PrismJS / PrismJS/prism

[Bug report] reloading markdown language will add wrap hook multiple times

Open
#2,716 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Information:

  • Prism version: 1.23.0
  • Plugins: 'none'
  • Environment: Node

Description

The reload logic is described here:

https://github.com/PrismJS/prism/blob/4e7b2a82d733fc705bc4a50192fb1bbe552bc687/dependencies.js#L383-L388

So the prism-markdown is possible to be reloaded multiple times, and the wrap hook will be added multiple times, too:

https://github.com/PrismJS/prism/blob/4e7b2a82d733fc705bc4a50192fb1bbe552bc687/components/prism-markdown.js#L320

For example:

  1. Load markdown and javascript
  2. Load jsdoc
    • jsdoc modifies javascript
    • javascript modifies markup
    • markup is depended by markdown
  3. So javascript, markup and markdown will also be reloaded

Then, syntax highlighting inside markdown code block will be triggered multiple times.

Example

  1. I tried to highlight markdown code:

image

  1. The wrap hooks are:

image

  1. Then the highlighted code:

image

image

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

Start with the reload logic in dependencies.js at the linked lines, then inspect the wrap hook registration in components/prism-markdown.js. Reproduce the markdown, javascript, and jsdoc reload sequence described in the issue; done means reloading dependencies does not register duplicate hooks or trigger repeated highlighting.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.