Phr*_*cis 6 html css pretty-print
我在让Google Code Prettify正常运行时遇到问题.此示例正在使用提供的远程文件:
<html>
<head>
<title>Google Code Prettify testing</title>
<script data-brackets-id='140' src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&skin=sunburst&lang=css" defer="defer">
</script>
</head>
<body>
<h1>Google Code Prettify testing</h1>
<pre class="prettyprint" style="font-size: 12pt;">
<script type="text/javascript">
// This is a comment
var myString = "Hello, World!";
var myInt = 42;
function helloWorld(world) {
for (var myInt; --myInt >= 0;) {
alert(myString);
}
}
</script>
<style>
p { color: pink }
b { color: blue }
u { color: "umber" }
</style>
</pre>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
结果:

这是来自Prettify远程主机.请注意,有些物品<script>仅用于造型和行为.以下工作正常:
<html>
<head>
<title>Prettify Default Test</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)
它只是使用默认的外观和行为呈现(请注意这是一个不同的浏览器)

但是,当我在本地下载并保存文件时,我写道:
<html>
<head>
<title>Google Code Prettify testing</title>
<link href="google-code-prettify/src/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="google-code-prettify/js-modules/run_prettify.js"></script>
</head>
<body onload="prettyPrint()">
<h1>Google Code Prettify testing</h1>
<pre class="prettyprint" style="font-size: 12pt;">
<script type="text/javascript">
// This is a comment
var myString = "Hello, World!";
var myInt = 42;
function helloWorld(world) {
for (var myInt; --i >= 0;) {
alert('Hello ' + String(world));
}
}
</script>
<style>
p { color: pink }
b { color: blue }
u { color: "umber" }
</style>
</pre>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
并且,以下,没有任何格式结转:

这是文件夹结构的快照.我已经验证确保在代码中准确引用了...


你能提供任何关于它为什么这样做的建议吗?
您的格式不起作用的原因是您为“run_prettify.js”文件引用了错误的路径。您将所有美化文件存储在 google-code-prettify/src/ 中,而您尝试链接到一个不支持该文件的文件夹不存在,例如 js-modules。
我已经在本地进行了测试,使用您提供的具有相同文件夹结构的确切源来复制您的环境,并通过仅渲染黑色字体的格式得出相同的结果。一旦我将其更改为“google-code-prettify/src/”,它就可以正常工作。
同样,要解决此问题,请更改路径:
<script type="text/javascript" src="google-code-prettify/js-modules/run_prettify.js"></script>
Run Code Online (Sandbox Code Playgroud)
到
<script type="text/javascript" src="google-code-prettify/src/run_prettify.js"></script>
Run Code Online (Sandbox Code Playgroud)
您可能遇到的唯一其他问题是某些浏览器(尤其是 IE)可能会阻止某些内容在您的浏览器中显示。如果您所在的网络强制阻止某些内容显示,或者在显示阻止的内容之前提示您授予许可,则您可能必须选择“显示阻止的内容”或类似的选项,然后才能按您希望的方式显示。
希望这可以帮助!
编辑:这对您来说是不必要的 - 但可能会帮助其他遇到类似情况的社区成员 - 但我想我还会参考“入门”部分,该部分涉及提供您自己的 JS 和 CSS 文件的要求以及如何启动和使用跑步。
https://code.google.com/p/google-code-prettif/wiki/GettingStarted#Serving_your_own_JS_&_CSS
| 归档时间: |
|
| 查看次数: |
607 次 |
| 最近记录: |