Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
meteorlxy opened this issue Jan 17, 2021 · 2 comments
Open

Comments

@meteorlxy
Copy link

meteorlxy commented Jan 17, 2021

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

@RunDevelopment
Copy link
Member

Thank you for the comprehensive bug report @meteorlxy!

I made a workaround for now. However, the underlying issue (that the wrap hook function is added multiple times) won't be as easy to solve, so this issue will likely be open for a while.

@meteorlxy
Copy link
Author

meteorlxy commented Jan 20, 2021

Yeah I understand the complexity of the underlying issue.

Currently we have to preload all possible languages to avoid such issue.

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

No branches or pull requests

3 participants
@meteorlxy @RunDevelopment and others