Skip to content

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

@meteorlxy

Description

@meteorlxy

Information:

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

Description

The reload logic is described here:

prism/dependencies.js

Lines 383 to 388 in 4e7b2a8

// add components to reload
// A component x in `loaded` has to be reloaded if
// 1) a component in `load` modifies x.
// 2) x depends on a component in `load`.
// The above two condition have to be applied until nothing changes anymore.

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

Prism.hooks.add('wrap', function (env) {

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions