question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using the plugins in NodeJS

See original GitHub issue

How can the plugins be used in NodeJS when importing like: import Prism from 'prismjs';

I tried to access the line-numbers plugin, but when I do Prism.plugins it’s an empty object.

Any ideas?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:16
  • Comments:23 (8 by maintainers)

github_iconTop GitHub Comments

8reactions
tigcommented, Jan 1, 2020

I was really expecting Prism’s line number support to work from node. Found this issue and I’m quite bummed.

I’m using node.js to generate static html files from code, formatting them with prismjs, so there’s no DOM to access.

6reactions
lunelsoncommented, Mar 8, 2019

AFAICT currently some plugins are using Node’s global object to pick up Prism and register the plugins. The following two work, but other plugins do not do this. Ultimately the best solution is probably to copy the body of the IIFEs in those files in to the file where you require Prism.

global.Prism = require('prismjs');
require('prismjs/plugins/normalize-whitespace/prism-normalize-whitespace');
require('prismjs/plugins/data-uri-highlight/prism-data-uri-highlight');

Object.keys(Prism.plugins); // [ 'NormalizeWhitespace', 'dataURIHighlight' ]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Build a Plugin System With Node.js - Fusebit
Writing a plugin system enables your application to be extensible, modular, and customizable. This is a guiding principle for the most ...
Read more >
Build A Plugin System — Node.js | Medium
A plugin is an extra piece of code that expands what a program can normally do. Web extensions are a good example of...
Read more >
Plugin architecture in JavaScript and Node.js with Plug and Play
Plug and Play helps library and application authors to introduce a plugin architecture into their code. It simplifies complex code execution ...
Read more >
node-plugins - npm
An extension-point based open plugin framework. Latest version: 1.0.3, last published: 2 years ago. Start using node-plugins in your project ...
Read more >
How to build a plugin system with Node.js - Technology Blog
How to build a plugin system with Node.js ... If you're building a minimalist product, but want to add an extra level of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found