61

Is there a content delivery network (CDN) that is hosting google-code-prettify?

I am putting together a blog on TypePad and would like to take advantage of a CDN if possible.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ahsteele
  • 26,243
  • 28
  • 134
  • 248
  • 3
    + 1 Google doesn't seem to host prettify for some reason, odd: http://code.google.com/apis/ajaxlibs/documentation/#jquery – Kane Feb 19 '10 at 07:14
  • 4
    @Kane I've made a suggestion that it be added: http://code.google.com/p/google-ajax-apis/issues/detail?id=393. Based on the lack of answers here I am guessing it's going to be a wait until Google adds it. – ahsteele Feb 19 '10 at 20:19
  • 2
    I wish they would, because: http://meta.stackexchange.com/questions/96519/is-it-legal-to-use-the-content-delivery-network-cdn-which-belongs-to-stack-exch – Jeff Atwood Jun 27 '11 at 06:33
  • 1
    We should all "heavily lobby Google to host this" as Jeff says. Click the star icon next to Issue 393 on the link @ahsteele provided: http://code.google.com/p/google-ajax-apis/issues/detail?id=393 – Banjer Jun 22 '12 at 12:52

5 Answers5

34

Found it!

http://www.cdnjs.com/libraries/prettify

<script src="http://cdnjs.cloudflare.com/ajax/libs/prettify/r298/run_prettify.js" type="text/javascript"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.css" type="text/css">

Update: https://github.com/cdnjs/cdnjs/issues/695 (see bottom of page)

mscccc
  • 2,190
  • 6
  • 25
  • 39
Rajish
  • 6,755
  • 4
  • 34
  • 51
  • 5
    Yes, but where is the .css file? – Andrew Arnott Jun 08 '12 at 19:43
  • Not all the language files are listed comparing to the files hosted on Google Code. Is it just not showing? What happens when the requested language is not there on CloudeFare? – gavsiu Mar 07 '13 at 03:15
  • +1 I would have chosen @Peter Dietz answer for its simplicity. But your's works too http://jsfiddle.net/9LY48/3/ fwiw its a little hard to tell it was working until I added lang-css to the classname... Helps to read the docs I guess. – Shanimal Jul 13 '13 at 09:20
  • For rev 298 : r298/prettify.js did not work for me, r298/run_prettify.js did work. – Deleplace Jul 28 '13 at 15:26
  • The problem with this is that you cannot use URL configurations, like skin. Visit [the code-prettify repo](https://github.com/google/code-prettify) to get the latest CDN url. – m.spyratos Sep 27 '16 at 00:52
4

You can use Google Code Prettify directly.

Read their Google Code Prettify Readme or wiki, and they tell you how to use them as the hosting provider.

<script
 src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"
 type="text/javascript"></script>

Then to use the prettyprint powers of Google Code Prettify, add class="prettyprint" to your code blocks, which should be in a pre or a code. Examples below:

<pre class="prettyprint">...</pre>

or

<code class="prettyprint">...</code>
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
Peter Dietz
  • 2,599
  • 1
  • 24
  • 23
  • 1
    It does work, but slows down my site because (1) does not always responds within a second and (2) most important, the Expire header is not correctly set in the future, so browser cache cannot do his job – Deleplace Jul 28 '13 at 15:19
4

There is a CDN for prettify:

https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js

Its use is explained on the official code-prettify repository. You can use it with a skin, like this:

<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js?skin=desert"></script>

That way you don't have to worry about additional CSS files. For more details and a full list of URL configurations, check the Getting Started section.


As mentioned by Jan Šotola, the previous RawGit CDN was shut down.
Read more details on migrating away from deprecated RawGit.

m.spyratos
  • 3,823
  • 2
  • 31
  • 40
  • 1
    RawGit CDN is shutting down. It is recommended to use jsDelivr CDN instead. https://groups.google.com/forum/#!topic/js-code-prettifier/IFHev_kLm30 – Jan Šotola Feb 06 '20 at 14:06
4

I believe you could use it directly from Google Code though.. ? embeding
http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js

tXK
  • 712
  • 6
  • 11
-2

You could create an account on Dropbox and put all the JavaScript and CSS files in the public folder. This worked for me!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bernhard Heijstek
  • 2,041
  • 1
  • 16
  • 20