PrismJS / PrismJS/prism

Add a way to remove hooks

Open
#1,993 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Motivation
Sometimes Prism has to reload languages (and soon plugins). This is a problem because the added hooks cannot be removed which will lead to multiple runs of the same hook.

Even if this doesn't cause highlighting issues, it's just unnecessary CPU time to execute the same hook multiple times.

Description
Require all callbacks added to a specific hook to have a name. The name of a callback should be the id of the language/plugin which added it.
If no name is provided, the callback will still be added but cannot be removed.

A new method Prism.hooks.remove(name: string): void can then be used to remove the callbacks of all hooks with the given name.

Alternatives
Instead of introducing a remove method, we could modify the add method to overwrite old callbacks with the same name. Callbacks without a name won't be overwritten.


Related: #459

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 at the Prism.hooks.add entry point and trace how callbacks are stored for each hook. Define how named callbacks are tracked and removed through Prism.hooks.remove, while preserving unnamed callbacks. Verify that removing a name removes its callbacks from every hook without affecting other callbacks.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.