如何对文章中的代码添加代码高亮


  1. 使用 highlight.js

    在页面中添加,如下代码 ^1

    <link rel="stylesheet" href="/path/to/styles/default.css">
    <script src="/path/to/highlight.pack.js"></script>
    <script>hljs.initHighlightingOnLoad();</script>
  2. 使用 syntaxhighlighter

    syntaxhighlighter

    <link type="text/css" rel="Stylesheet" href="PATH/Styles/shThemeDjango.css"/>
    <script src="syntaxhighlighter.js"></script>
    <script>
    syntaxhighlighterConfig = &#123;
      className: 'custom-class-name'
    &#125;;
    </script>

参考文档


Author: Itaken
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Itaken !
  TOC目录