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 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.
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 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 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.
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`.
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.
github: https://github.com/phoboslab/jQuery-JSH
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.
The bigger regExps you write, the slower and more bug-prone your code will be.
http://craig.is/making/rainbows (1.4kb) http://softwaremaniacs.org/soft/highlight/en/
I prefer
http://pygments.appspot.com
Pretty in Chrome Canary Version 22.0.1221.0 though.
The code snippets are overlayed with black 'blocks'.
But the site's index.html is using only a pre tag:
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/
This is just a syntax highlighter for embedding code examples in your site/blog.