News for hackers. Stuff that matters.
Re:PrismJS by tikhonj on Tuesday July 31, 2012 @04:47AM (#4316304)
Is there any particular advantage to using something like this for static code samples instead of just pre-rendering the HTML and CSS?

I usually just export my code from Emacs via M-x htmlfontify-buffer which dumps a bunch of CSS and HTML. This also allows me to take advantage of my different Emacs themes. It also outputs CSS with good class names like "string" or "keyword". If you add your own custom faces, it just uses the name you gave them. This means the coloring is exactly as customizable as it is in Emacs. It is also very easy to theme with CSS to match your site if you don't like any of the Emacs color themes.

Re:PrismJS by jergason on Tuesday July 31, 2012 @05:45AM (#4316432)
I have used Vim's similar feature, `:TOhtml`.
Re:PrismJS by phoboslab on Tuesday July 31, 2012 @06:55AM (#4316585)
If you want an even smaller (sans jQuery) JS highlighter that doesn't fail on edge cases, check my jQueryJSH: http://www.phoboslab.org/files/jquery-jsh/

github: https://github.com/phoboslab/jQuery-JSH

Re:PrismJS by jacobr on Tuesday July 31, 2012 @07:50AM (#4316741)
1) How do I know it doesn't fail on the same edge cases Prism might fail on? I see no tests.

2) Do you really need jQuery there? You seem to be using it only for the html method, and including 93K extra JS instead of just using innerHTML seems a bit overkill.

Re:PrismJS by Xurinos on Tuesday July 31, 2012 @08:08AM (#4316794)
2) Do you really need jQuery there? You seem to be using it only for the html method, and including 93K extra JS instead of just using innerHTML seems a bit overkill.

It checks for the case that .innerHTML setting is not supported (I think that was for certain versions of IE) and switches to using appendChild(). I think that that small oversight is somewhat reasonable justification for using a wrapper that abstracts away the browser differences, although it can be argued that once someone understands the differences, they could just add the use cases to their code.

Re:PrismJS by saurik on Tuesday July 31, 2012 @10:12AM (#4317304)
I am somewhat confused why you would trust tests for edge cases sufficiently strongly so as to distrust an implementation without any; edge cases should be proved from first principals, as you can't possible test all of them.
Re:PrismJS by jarek-foksa on Tuesday July 31, 2012 @08:19AM (#4316824)
But smaller does not always mean better. Benchmarks have shown that parsers based exclusively on regular expressions can be even several times slower than parsers that use scanner/tokenizer.

The bigger regExps you write, the slower and more bug-prone your code will be.

Re:PrismJS by lukeholder on Tuesday July 31, 2012 @03:43AM (#4316155)
Re:PrismJS by moomin on Tuesday July 31, 2012 @06:28AM (#4316532)
I don't think the author really understands IE usage patterns. The majority of IE6 usage isn't individuals who don't know better, its companies who should know better. Hence, you'll still get plenty of intelligent coders using IE.
Re:PrismJS by slig on Tuesday July 31, 2012 @07:20AM (#4316647)
Intelligent coders should know better than to be forced to work with IE6. What would be the server side technology in this case? JSP filled with code and SQL or ASP classic?
Re:PrismJS by countessa on Tuesday July 31, 2012 @09:46AM (#4317182)
Um....no. Intelligent coders understand that there are always limitations placed on them and accept that to produce quality code, they need to understand their environment and code for the end user.
Re:PrismJS by gyaresu on Tuesday July 31, 2012 @04:05AM (#4316205)
Not working in Opera 12.00 Build 1467 on OS X 10.7.4

Pretty in Chrome Canary Version 22.0.1221.0 though.

Re:PrismJS by darklajid on Tuesday July 31, 2012 @04:46AM (#4316302)
Neither working (and so far the only really bad rendering issue I've seen) on Android, using Firefox Beta.

The code snippets are overlayed with black 'blocks'.

Re:PrismJS by graue on Tuesday July 31, 2012 @03:30PM (#4319183)
I'm confused. In the features list: "Prism forces you to use the correct element for marking up code: <code>."

But the site's index.html is using only a pre tag:

  <p>The Prism source, highlighted with Prism (don’t you just love how meta this is?):</p>
  <pre data-src="prism.js"></pre>
It looks like the script is automatically expanding this, inserting <code> tags along with the named file, but I don't see any documentation for doing it this way.

Also, if anyone is as confused as I was about why there's a "data-src" attribute, apparently it's an HTML5 data attribute: http://ejohn.org/blog/html-5-data-attributes/

Re:PrismJS by nodesocket on Tuesday July 31, 2012 @04:10AM (#4316223)
Lovely. Google code-prettyify (http://code.google.com/p/google-code-prettify/) is great as well, but Prism looks more aesthetically appealing. Would love to have additional languages `perl`, `python`, `ruby`.
Re:PrismJS by czzarr on Tuesday July 31, 2012 @05:59AM (#4316464)
someone please make a vim colorscheme that looks like the light scheme of prism. it is gorgeous
Re:PrismJS by devgutt on Tuesday July 31, 2012 @10:02AM (#4317251)
Unfortunately I haven't found any similar at http://vimcolorschemetest.googlecode.com/svn/html/index-html...
Re:PrismJS by dytrivedi on Tuesday July 31, 2012 @06:36AM (#4316545)
Ditto. I'd love this as a vim colorscheme.
Re:PrismJS by peteretep on Tuesday July 31, 2012 @04:37AM (#4316286)
For the "fails on certain edge cases" link, I'd have rather they'd linked to SelfGol (https://www.socialtext.net/perl5/selfgol)
Re:PrismJS by Kartificial on Tuesday July 31, 2012 @04:01AM (#4316196)
The text-shadow in the dark theme needs a little getting used to but looks pretty nice in the end.
Re:PrismJS by drivebyacct2 on Tuesday July 31, 2012 @03:37AM (#4316139)
Can anyone compare this to CodeMirror which seems to include this functionality and much, much more?
Re:PrismJS by lukeholder on Tuesday July 31, 2012 @03:44AM (#4316160)
CodeMirror is a "full" syntax highlighted code editor.

This is just a syntax highlighter for embedding code examples in your site/blog.

Re:PrismJS by drivebyacct2 on Tuesday July 31, 2012 @05:00AM (#4316336)
Right, but CodeMirror can be used as a simply syntax highlighter as well.
Re:PrismJS by ajankovic on Tuesday July 31, 2012 @06:02AM (#4316473)
This one is around 2k in size, therefor "lightweight"