使用Google Prettify显示HTML [英] Using Google Prettify to display HTML
本文介绍了使用Google Prettify显示HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要让Google Prettify正确显示HTML代码示例,您应该将所有<
替换为& lt;
以及所有>
,& gt;
。
for Google Prettify to display HTML code sample properly, you should replace all the <
with <
and all the >
with >
.
如何仅使用JavaScript自动执行该过程?
How do you automate that process using JavaScript only ?
推荐答案
如果将代码置于 < xmp>
元素,您无需转义HTML特殊字符,如测试
<h1>HTML using XMP</h1>
<xmp class="prettyprint" id="htmlXmp"
><html>
<head>
<title>Fibonacci number</title>
</head>
<body>
<noscript>
<dl>
<dt>Fibonacci numbers</dt>
<dd>1</dd>
<dd>1</dd>
<dd>2</dd>
<dd>3</dd>
<dd>5</dd>
<dd>8</dd>
…
</dl>
</noscript>
<script type="text/javascript"><!--
function fib(n) {
var a = 1, b = 1;
var tmp;
while (--n >= 0) {
tmp = a;
a += b;
b = tmp;
}
return a;
}
document.writeln(fib(10));
// -->
</script>
</body>
</html>
</xmp>
这篇关于使用Google Prettify显示HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文