无法使用higlightjs突出显示HTML代码

时间:2017-11-08 17:39:43

标签: javascript highlightjs

我在这里做了一个小文件



<!DOCTYPE html>
<html>
<head>
    <title>highlightjs</title>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/darcula.min.css">

</head>
<body>

    <pre>
        <code class="php">
            namespace App\Http\Controllers;

            use Illuminate\Http\Request;
            use DB;
            use Session;

            class ProductController extends Controller
            {
                /**
                 * Show the application dashboard.
                 *
                 * @return \Illuminate\Http\Response
                 */
                public function index()
                {
                    $posts = DB::table("posts")->get();
                    return view('posts',compact('posts'));
                }

                /**
                 * Show the application dashboard.
                 *
                 * @return \Illuminate\Http\Response
                 */
                public function destroy($id)
                {
                    DB::table("posts")->delete($id);
                    Session::put('success', 'Your Record Deleted Successfully.');
                    return redirect()->route('posts');
                }
            }
        </code>
    </pre>

    <pre>
        <code class="xml hljs">    

            <body>
                <p class="title" id='title'>Title</p>

                <h2>Why is this HTML code not highlighted?</h2>

                &ltp&gtTeeeeest&lt/p&gt
            </body>

        </code>
    </pre>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</body>
</html>
&#13;
&#13;
&#13;

我试图在此网站上突出显示HTML代码:

DEMO

它不起作用。他正在做的事情可能不是我。但是什么? 我的PHP正确突出显示。如何突出显示HTML代码?

1 个答案:

答案 0 :(得分:2)

替换&lt;带有&lt;和&gt;的字符代码标记内包含&gt;的字符。