Comments (12)
No, as I have no idea how to do that :P
But if you want to help, that would be welcome :)
from prism.
@jzaefferer How would that work exactly, given Prism.js heavily relies on (non-ECMAScript) DOM extensions for most of its core methods?
from prism.
@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
from prism.
@mathiasbynens The heart of Prism is Prism.highlight()
, Prism.tokenize()
and Prism.Token.stringify()
. Neither of those use DOM methods.
from prism.
@LeaVerou Oh, thatβs good news, then!
from prism.
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
from prism.
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.
from prism.
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.
from prism.
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
from prism.
Based on further discussion, a new version has been submitted that creates a dedicated node version of prism.js.
The pull request is: #45
from prism.
This can be closed since #179 was merged, right?
from prism.
I think so :)
from prism.
Related Issues (20)
- Add support for caddyfile (caddy)
- Show-invisibles plugin throws TypeError exception with Dart and Lisp languages
- Add support for CoNLL-U framework
- JavaScript syntax number strings rendered with an offset HOT 2
- Highlighting working in TinyMCE, but not website
- Library broken in Service worker HOT 1
- Masm, Nasm, Fasm or just asm
- Unterminated parenthetical HOT 2
- [CSharp] Attributes following comments are either mis-tagged or not tagged as `class-name`
- Microsoft Typespec
- C# `file` keyword/accessibility modifier is not highlighted
- Crowdstrike/LogScale/Humio syntax highlighting
- Jsonnet language syntax support
- Support for VEX, SideFX Houdini's scripting language
- [Language request] Smithy support
- Overwrites autoloader path HOT 2
- Add support for Lean (lean) HOT 1
- [Language Request] Mojo by Modular
- Add syntax highlighting for GNU Autotools
- Bash syntax highlighting is weak compared to highlight.js
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prism.