【发布时间】:2016-05-16 19:27:48
【问题描述】:
我正在尝试实现 highlight.js。 我有 index.html。身体的侧面是
<p>Example code</p>
<pre>
<code class="html">
<title>Title</title>
<style>body {width: 500px;}</style>
<script type="application/javascript">
function $init() {return true;}
</script>
<body>
<p checked class="title" id='title'>Title</p>
<!-- comment to be highlighte -->
</body>
</code>
</pre>
但是当我加载页面时,<pre> 中的任何内容都会被处理为真正的 html,它会破坏页面,页面上使用的主要 css 也会应用于 中的标签
在我的 index.html 的头部,我已经包含了
<link rel="stylesheet" type="text/css" href="../css/highlight.css">
在我包含的正文结束标记之前
<script src="../scripts/highlight.pack.js"></script>
<script>
$(document).ready(function() {
$('pre code').each(function(i, block) {
hljs.highlightBlock(block);
});
});
</script>
我一直在阅读文档,但似乎无法找出我错过了什么。
【问题讨论】:
标签: javascript html css syntax-highlighting highlight.js