使用 Google Code Prettify CDN 和自定义皮肤

Using Google Code Prettify CDN with a custom skin

我正在使用 Google Code Prettify CDN link:

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

根据设计,它将 CSS 样式 sheet 附加到 DOM:

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

如果您想使用默认皮肤(或项目提供的 URL 参数定义的皮肤之一),这很好,但就我而言,我想使用自定义主题:

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

呃哦,GCP 在 我的主题之后附加了它的主题 ,所以现在我的所有样式都被覆盖了。

有没有办法使用 GCP CDN(或 a CDN)自定义样式sheet将 !important 添加到 sheet 中的每个样式?还是我一直在下载 GCP 并将其本地包含在我的项目中?

您可以使用 non-autoloader 版本,即 https://cdn.rawgit.com/google/code-prettify/master/loader/prettify.js

并在页面准备就绪时执行 PR.prettyPrint()。不会下载样式表。