Add Node.js support #179
Add Node.js support #179
Conversation
I also confess that I couldn't instantly see a build system, so I just copied the changes from one file to another. I also wasn't sure how the minified files actually got produced, so I just left them alone - I hope that's OK. |
Ah - I seem I'm not the only person to have proposed this. If this isn't suitable, would you be able to tell me what kind of thing you'd be looking for in a Node adaptation? I would very much like to see Prism in NPM, but I can understand if you have strong views about what happens to your codebase. |
Hi there! Thank you so much for doing this. This looks perfect, I wanted to add Node support with a minimum amount of changes for a long time. However, I will need someone to review this who does code in Node, as I don't. Any takers? You don't need to edit prism.js, that's just the version of Prism used by the website and is built automatically. It would make the changes easier to review if you removed the ones about prism.js. Regarding the build system, I'm using CodeKit locally, which isn't optimal as everyone is confused. At some point I will need to export my configuration somehow in a config file and include it in the repo. Currently the configuration is just a bunch of CodeKit settings :( |
+1 on this @LeaVerou! I'm building a touch typing trainer for code (similar to typing.io) using Node and Browserify, and I'd love to use Prism for syntax highlighting. I'm really impressed with it's simplicity, I think you're doing an awesome job. I looked over @geraintluff's commit, and it looks solid. I do however recommend that you spend some time getting comfortable with Node if you finally decide to merge it in. On the flipside, Node is a great support tool for any type of general web development, so it won't be time wasted. Writing modular code using Browserify and automating build tasks with Grunt.js are things I really recommend looking into. |
I would love to use this with Browserify, however there's already a package named prism, though it's not really anything. Besides that it's this getting accepted any time soon? |
If it would help this get merged, I'd be happy to be first contact for future Node-specific issues. I've already been using my modified fork to do server-side code-highlighting, and I'd love for it to be more official. :) |
@@ -4,13 +4,15 @@ | |||
Begin prism-core.js | |||
********************************************** */ | |||
|
|||
var self = (typeof window !== 'undefined') ? window : {}; |
LeaVerou
Apr 21, 2014
Contributor
prism.js is just the version of prism used in the website, you don't need to modify this file.
prism.js is just the version of prism used in the website, you don't need to modify this file.
geraintluff
Apr 23, 2014
Author
Contributor
Right now, package.json
references this prism.js
. If you think it would be better-off referencing something else, then I'm happy to change it.
My reasoning was that if it just referenced prism-core.js
then it wouldn't appear pre-loaded with various languages.
Separate JS files don't share a global namespace in Node, so adding the ability to load these languages individually would require more (possibly awkward) code-changes, and I wasn't sure if there would be any benefit. The simplest thing seemed to be to reference what looked like a grand-bundle of stuff.
Right now, package.json
references this prism.js
. If you think it would be better-off referencing something else, then I'm happy to change it.
My reasoning was that if it just referenced prism-core.js
then it wouldn't appear pre-loaded with various languages.
Separate JS files don't share a global namespace in Node, so adding the ability to load these languages individually would require more (possibly awkward) code-changes, and I wasn't sure if there would be any benefit. The simplest thing seemed to be to reference what looked like a grand-bundle of stuff.
Finally found some time to review this properly, sorry for the delay! Merged!! |
Can anyone help with publishing to npm? Too busy to research it right now. Thanks! |
Hi Adam, I made an npm account, but I'm still not sure how to publish... |
@LeaVerou at the root of the project;
As far as I remember from Fluent you have a Mac so you might get an error running those above like I did but there's an easy fix. |
+1 on all of this. Thanks! |
@LeaVerou - Thanks for the merge. :) I'm also happy to help out if there are any issues publishing to NPM. |
In advance of this, I've been trying to install directly from this github repo. For example:
...and so forth. I have encountered an error on every attempt. I'm not sure if this will be resolved when published to NPM or if there is an issue in how the package has been set up. Has anyone successfully installed from this repo and/or are we confident the package is ready for publishing? |
Not working for me either.
npm wants to download the 'master' branch, but it does not exists since everything is in the 'gh-pages' branch. |
If a Git repo doesn't have a If you want to test-drive the package, give something like the following a go:
This should have no effect on "ordinary" installation from NPM (because that doesn't rely on Git at all, storing the code locally instead). (BTW, when trying a "git+ssh://" URL I get "Permission denied (publickey)" - but I get the same thing when doing a |
Good to know, thanks @geraintluff. |
I was hoping to use Prism on Node.js - this PR adds Node support, without changing browser behaviour. I've tried to keep the changes as small as possible:
self
is declared as a variable (equal towindow
in the browser, or{}
in Node).Prism
is declared as a variable inprism-core.js
so that other files (like language definitions) can use itmodule.exports
is defined, then it is assigned toPrism
.self.addEventListener
I believe these should have no effect on a browser environment, and
test.html
still works for me, at least.Obviously, most of the methods don't work in Node, but I don't see a great benefit in removing them. Node usage:
If you feel like it, it should be ready to just
npm publish
.