-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Importing all languages in node.js #972
Comments
It would be nice to have this indeed, and it can be automatically generated via gulp… |
I digged into this last night, and the loadComponent() option works great. It might even be able to handle dependencies by reading the |
Would it help if we split components.js to a components.json which can be easily parsed and then create components.js + module.exports with gulp? |
@LeaVerou Indeed that would be nice! But shouldn't it be considered a BC break anyway, since people relying on parsing the |
No, because components.js would still exist, it would just be generated with gulp! :) Also I don't think that many people are relying on components.js :P |
@LeaVerou I'm working on an integration that might require access to a Currently, the |
Are there any updates on this? Being able to pull in additional languages via npm would be great! |
This pattern works well #593 (comment) |
i am using prismjs highlighter in nodejs, able to highlight the code but it fails to give line number although i have added the line number plugin and line-numbers class to the target |
Ok, we added a var Prism = require('./components/prism-core.js');
var loadLanguages = require('./components/index.js');
loadLanguages(['php', 'ruby']);
Prism.highlight(...); It will load the required dependencies. I still need to document this somewhere. I'll close the issue once it's done. |
Requiring components without the "index.js" part and calling "loadLanguages" results in a function not found error for me. Adding index.js, as commented by @Golmote, fixes that error. Ref: PrismJS#972
* Updated index.html to fix broken instructions Requiring components without the "index.js" part and calling "loadLanguages" results in a function not found error for me. Adding index.js, as commented by @Golmote, fixes that error. Ref: #972 * Updated index.html to fix nodejs instructions Fixed the require so that nodejs does not give an error when requiring the loadLanguages function.
@Golmote Could you add the link to the documentation? |
Struggling to get this to work in Typescript as well. Update: Could get Typescript to work on Node using require like so:
|
I found that if you don't specify an array of languages, all of them will be loaded. In TypeScript, I was able to load all languages using this syntax:
|
You can easily import it in NodeJS: import Prism from 'prismjs'
// @ Load Prism languages
import 'prismjs/components/prism-markup-templating' // dependency for prism-php extension
// PHP
import 'prismjs/components/prism-php' |
Could this issue be reopened? I would still like to see a language loader method similar to prismjs |
I believe this will be a lot easier in v2, which means there's less motivation to fix it in v1. |
This is related to: #593
The components are injected when you require the module, so can we have (for the node users) an
index.js
insidecomponents
folder, that does this?So then we only have to use:
Or even something like:
This won't work in the browser i think, but why not have this simple helper for the node users?
The text was updated successfully, but these errors were encountered: