PrismJS / PrismJS/prism

Allow for external highlighting and worker support

Open
#817 0 comments 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

Hello,

continuing work on prism-grammar which adds alternative external parsing to Prism, a way is asked to make external parsing (a kind of plugin lets say) more compatible with Prism (v.1.2.0). Including Web Worker support.

For example right now the prism-grammar uses prism hooks to parse the code with its own parser and at the same time minimise prism parsing, since prism does not have a support for external parsing and will parse the same code twice (once with its own tokenizer and once through the prism-grammar)

The prism-grammar saves this by reseting the code to be highlighted before-highlight (so prism tokenizer will just see an empty string) and then resets the code on another hook so parsing is done only once.

The above scheme works for this purpose. However prism also uses (or can use) a web worker to do the parsing/highlighting job and this is not available in an external parser, which has to do any parsing in the main thread. Since worker parsing requires an async callback which is not available in hooks (which prism-grammar uses) and which run synchronously.

The prism-grammar add-on works as is right now. However it would be good to maximise the efficiency by being able to hook on worker parsing through prism (e.g via a callback or sth). So this issue asks for support to hook into worker used by prism, as a first step (and maybe eventualy add full support for external parsing add-ons).

In other words think of a tokenizer that is external to prism and can communicate through interfaces or callbacks (including async callbacks). For example, to hook into the prism worker, a plugin or external parser could provide its own workerUrl, to be instantiated as a worker, and return data that is compatible with what prism worker would return (this can be an option to settle this issue as a first step)

a related issue i had posted earlier (https://github.com/PrismJS/prism/issues/196) can be merged into this issue (closing that issue)

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 reading Prism's hook interfaces and worker parsing flow, then compare them with the external parser behavior described for prism-grammar. Define the worker or callback contract, including workerUrl and async results, and document how compatible returned highlighting data would be validated.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.