Skip to content
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

Publish on npm #12

Closed
jzaefferer opened this issue Jul 31, 2012 · 12 comments
Closed

Publish on npm #12

jzaefferer opened this issue Jul 31, 2012 · 12 comments

Comments

@jzaefferer
Copy link

This looks like it would be useful to run serverside via node.js. Could you add a package.json and publish on npm?

@LeaVerou
Copy link
Member

No, as I have no idea how to do that :P
But if you want to help, that would be welcome :)

@mathiasbynens
Copy link
Contributor

@jzaefferer How would that work exactly, given Prism.js heavily relies on (non-ECMAScript) DOM extensions for most of its core methods?

@jzaefferer
Copy link
Author

@mathiasbynens no idea, haven't looked at the code yet, but that sounds like it would become a problem. Though jsdom, or even better yet, cheeriosjs, might help there: https://github.com/MatthewMueller/cheerio

@LeaVerou
Copy link
Member

@mathiasbynens The heart of Prism is Prism.highlight(), Prism.tokenize() and Prism.Token.stringify(). Neither of those use DOM methods.

@mathiasbynens
Copy link
Contributor

@LeaVerou Oh, that’s good news, then!

@tbranyen
Copy link

https://github.com/LeaVerou/prism/blob/gh-pages/prism.js#L300

would need to be changed before this script could run in node without a ReferenceError

@jzaefferer
Copy link
Author

Also usage of self would need to be replaced. Within the node context, module.export = Prism would be the right way to expose that object.

@buymeasoda
Copy link

Hi folks,

I've done some work to adapt the current prism.js code to work within a node context, as well as the browser.

To see the changes involved, have a look at the following branch / diff for the details:

Diff: https://github.com/buymeasoda/prism/compare/npm-node-support
Branch: https://github.com/buymeasoda/prism/tree/npm-node-support

This version allows you to do the following:

$ node

> var prism = require('./prism.js');
> prism.highlight('var test = "my string";', prism.languages.javascript);

'<span class="token keyword" >var</span> test <span class="token operator" >=</span> <span class="token string" >"my string"</span><span class="token punctuation" >;</span>'

I've included a sample package.json file for publishing to npm and will add a pull request to give you some more visibility of the merge results.

Although this adaption is working fine for providing require support, I think the node / npm side of things could be improved further with some changes to the way the base project files are organised.

The plugins that work in a node (non-browser) context, have also had a couple of minor changes to allow them to work. For example, Show Invisibles and Autolinker are both usable scripts in a node context.

Let me know what you think and if there's anything else I can do to help.

@buymeasoda
Copy link

Based on feedback from Lea, I've created a new version of this pull request that includes the bare minimum needed to get Prism functioning in node.

The pull request is: #42

@buymeasoda
Copy link

Based on further discussion, a new version has been submitted that creates a dedicated node version of prism.js.

The pull request is: #45

@adam-lynch
Copy link
Contributor

This can be closed since #179 was merged, right?

@LeaVerou
Copy link
Member

I think so :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants