A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/PrismJS/prism/issues/2736 below:

Explicitly add languages and plugins · Issue #2736 · PrismJS/prism · GitHub

Motivation

Right now, Prism has a few problems with how languages and plugins are added/loaded. To list a few of those problems in no particular order:

All of these problems come from the fact that Prism instances have no control over their languages/plugins.

This issue proposes a new API to add languages and plugins that can be used to solve all of the above-mentioned problems.

Description

Instead of adding languages/plugins directly to Prism.{languages,plugins}, new functions Prism.{languages,plugins}.add will be used. The add functions will take 3 pieces of information:

  1. The id of the language/plugin.
  2. A function created the language/plugin.
  3. Optional meta information such as aliases.

The add functions will do 3 things:

  1. Add meta information and the function creating the language/plugin to an internal (or public?) registry.
  2. Run the creator function to actually add the language.
  3. Add aliases (if any).
API
/**
 * @param id The id of the language/plugin.
 * @param meta Information about the language/plugin.
 * @param createFn A function that add the language/plugin to the given Prism instance.
 */
Prism.{languages,plugins}.add(
	id: string,
	meta: Meta,
	createFn: (Prism: Prism) => void
): void;

interface Meta {
	/**
	 * A list of aliases of the current language/plugin.
	 */
	alias?: string | string[];
}
Usage
Prism.languages.add('my-lang', { alias: 'my-language' }, Prism => {
  Prism.languages['my-lang'] = { ... };
});

Note that this usage pattern is very compatible with the current way languages/plugins are added.

Advantages Disadvantages

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4