PrismJS / PrismJS/prism

"wrap" hook is only called on Token, but there is no way to hook a string, which could be a symbol

Open
#3,711 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Motivation

At the moment "wrap" doesn't wrap non-highlighted items.

Description

I'm trying to write a simple plugin that would highlight my own classes and constants that are exported by a C++ library.

I tried to use something like this:

Prism.hooks.add("wrap", function(e) {
  if (e.language === "cpp") {
    console.log(e.content);
    // ... handle the case here ...
  }
});

However, the callback is not called on symbols, look at this small program:

void x() {
  Result r;
  Context ctx;
  // ... something else ...
}

The highlighter misses to call wrap with "Result", "r", "Context", and "ctx" tokens, so I cannot really influence how these would be highlighted.

Alternatives

I don't know about any - I followed the keywords highlighter plugin.

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 by tracing Prism's "wrap" hook during highlighting and compare its behavior on the supplied C++ example, especially the unhighlighted symbols Result, r, Context, and ctx. Define how hook callbacks should represent string symbols, then verify that the requested symbols can be influenced without changing the existing handling of highlighted tokens.

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
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.