基本的highlightjs文档不起作用

时间:2015-05-09 18:02:17

标签: syntax-highlighting

Highlightjs有非常简单的usage指令,我似乎无法在下面的文档中使用它。我希望显示<pre> and <code>中的html,但我看到的只是文字。我做错了什么?

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>  

	<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/styles/default.min.css">
	<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/highlight.min.js"></script>
	<script>hljs.initHighlightingOnLoad();</script>
</head>

<body>
	
<pre>
	<code class="html">
		 <!DOCTYPE html>
		 <html lang="en">
		 <head>
			 <meta charset="UTF-8">
			 <title>Document</title>
		 </head>
		 <body>
			<p>This should be escaped, highlighted html. </p>
		 </body>
		 </html>
	</code>
</pre>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

答案是highlightjs不会像我所建议的那样逃避代码。良好的链接here

&#13;
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>  

  <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/styles/default.min.css">
  <script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
</head>

<body>
  
<pre>
  <code class="html">
     &#x3C;!DOCTYPE html&#x3E;
     &#x3C;html lang=&#x22;en&#x22;&#x3E;
     &#x3C;head&#x3E;
       &#x3C;meta charset=&#x22;UTF-8&#x22;&#x3E;
       &#x3C;title&#x3E;Document&#x3C;/title&#x3E;
     &#x3C;/head&#x3E;
     &#x3C;body&#x3E;
      &#x3C;p&#x3E;This should is highlighted html. &#x3C;/p&#x3E;
     &#x3C;/body&#x3E;
     &#x3C;/html&#x3E;
  </code>
</pre>

</body>
</html>
&#13;
&#13;
&#13;