HLJ 发布于
2022-01-21 14:31:01

单页面引用highlightjs使代码快高亮方式

  • 1、引用 https://highlightjs.org/static/demo/styles/default.css
  • 2、引用 https://highlightjs.org/static/highlight.site.pack.js
  • 3、调用 hljs.highlightAll() 函数

    实例代码

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
      <link rel="stylesheet" href="https://highlightjs.org/static/demo/styles/default.css">
      <script src="https://highlightjs.org/static/highlight.site.pack.js"></script>
      <script>hljs.highlightAll();</script>
    </head>
    <body>
    <div style="font-size: 18px;">
    <pre>
    <code class="language-javascript">
    let dom = document.querySelector('body')
    </code>
    </pre>
    </div>
    </body>
    </html>
    

    输出结果

    let dom = document.querySelector('body')
    
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2022-01-21/574.html
最后生成于 2023-06-27 21:38:06
此内容有帮助 ?
0