cssgoogle-code-prettify

Using Google Code Prettify CDN with a custom skin


I'm using the Google Code Prettify CDN link:

<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>

By design, it appends a CSS stylesheet into the DOM:

<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/google/code-prettify/master/loader/prettify.css">

This is great if you want to use the default skin (or one of the URL parameter-defined skins the project makes available), but in my case, I want to use a custom theme:

<link rel="stylesheet" href="css/my-custom-theme-that-is-awesome.css">

Uh oh, GCP appended its theme after mine, so now all of my styles are getting overwritten.

Is there a way to use the GCP CDN (or a CDN) and a custom stylesheet without having to add !important to every style in the sheet? Or am I stuck downloading GCP and including it locally in my project?


Solution

  • You can use the non-autoloader version, i.e. https://cdn.rawgit.com/google/code-prettify/master/loader/prettify.js

    And execute PR.prettyPrint() when the page is ready. No stylesheet will be downloaded.