From 59068d67bda2d10d28a1cef61fbb590ce6c5fe9b Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Sun, 5 Jan 2020 20:03:41 +0100 Subject: [PATCH] Added documentation for new dependency API (#2141) --- extending.html | 129 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 124 insertions(+), 5 deletions(-) diff --git a/extending.html b/extending.html index ed0d2f1c0b..de25798507 100644 --- a/extending.html +++ b/extending.html @@ -7,6 +7,7 @@ Extending Prism ▲ Prism + + +

Note: You can declare a component as both require and modify

+ +

Resolving dependencies

+ +

We consider the dependencies of components an implementation detail, so they may change from release to release. Prism will usually resolve dependencies for you automatically. So you won't have to worry about dependency loading if you download a bundle or use the loadLanguages function in NodeJS, the AutoLoader, or our Babel plugin.

+ +

If you have to resolve dependencies yourself, use the getLoader function exported by dependencies.js. Example:

+ +
const getLoader = require('prismjs/dependencies');
+const components = require('prismjs/components');
+
+const componentsToLoad = ['markup', 'css', 'php'];
+const loadedComponents = ['clike', 'javascript'];
+
+const loader = getLoader(components, componentsToLoad, loadedComponents);
+loader.load(id => {
+	require(`prismjs/components/prism-${id}.min.js`);
+});
+ +

For more details on the getLoader API, check out the inline documentation.

+ + + +

Writing plugins

@@ -377,6 +494,8 @@

Returns

+ +