2015-05-09 92 views
1

Highlightjs有非常簡單的usage說明,我似乎無法在下面的文檔中工作。我希望顯示<pre> and <code>內的html,但我看到的只是文本。我究竟做錯了什麼?基本highlightjs文檔將不起作用

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

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

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

 
</body> 
 
</html>

回答

0

答案是因爲有人建議我highlightjs不適合你逃脫代碼。良好的鏈接here

<!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>