PrismJS / PrismJS/prism

Autoloader Plugin: support alternative ways of loading the files

Open
#3,654 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

Motivation
I want to leverage the autoloader plugin to load language files on demand, but through another loading strategy other than a <script> tag.

Description
The autoloader plugin currently supports overriding of the default loadLanguages function in order to implement a custom loader:
https://github.com/PrismJS/prism/blob/59e5a3471377057de1f401ba38337aca27b80e03/plugins/autoloader/prism-autoloader.js#L321

However, what that means is that I will have to re-implement all of that useful logic found in both the loadLanguages and the loadLanguage functions: https://github.com/PrismJS/prism/blob/59e5a3471377057de1f401ba38337aca27b80e03/plugins/autoloader/prism-autoloader.js#L405-L496
where what I really wanted to was to implement a custom way of loading the file, which in your case is by adding a <script> tag to the web page:
https://github.com/PrismJS/prism/blob/59e5a3471377057de1f401ba38337aca27b80e03/plugins/autoloader/prism-autoloader.js#L478

Alternatives
The way I have implemented this is by patching your code during build time like this:

-                               addScript(getLanguagePath(lang), function () {
+                               Prism.plugins.autoloader.addScript(lang, function () {

and then I have the addScript function implemented in my code to load the file using message passing to another process instead.

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 in plugins/autoloader/prism-autoloader.js by reading the loadLanguages and loadLanguage functions, especially the addScript call around the referenced lines. Trace how the existing loading logic selects and loads language files, then define an extension point for replacing only the file-loading strategy. Done means callers can use an alternative loader without reimplementing the surrounding autoloader logic.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.