仿CSND實現網頁中程式碼高亮顯示

來源:互聯網
上載者:User

標籤:

關於SyntaxHighlighter 3.0.83的使用下載SyntaxHighlighter

可以到官方網站下載

在頁面引入
  • 引入shCore.js and shCore.css
  • 添加支援相應語言的js檔案
    需要支援什麼語言,就引入該語言對應的JS檔案
  • 引入shThemeDefault.css
  • 將需要高亮顯示的代碼放置在<pre /> 或是<script />中
  • 調用SyntaxHighlighter.all() 方法
執行個體

程式如下:

<meta charset="utf-8"><link type="text/css" rel="stylesheet" href="styles/shCore.css"/><link type="text/css" rel="stylesheet" href="styles/shCoreDefault.css"/><script type="text/javascript" src="scripts/shCore.js"></script><script type="text/javascript" src="scripts/shBrushPhp.js"></script></script><script type="text/javascript">    SyntaxHighlighter.all();</script><h1>測試</h1><pre class="brush: php;">  /**  *  *@author dequan  */   Class Person{    public function say(){        echo ‘hello world‘;    }  }      </pre>

效果如

將SyntaxHighlighter 整合到OneThink中的kindeditor中修改code.js檔案


將48行注釋掉,改為49行

在相應的現實視圖中添加syntaxhighlighter需要的CSS以及JS檔案

測試

前端預覽(http://www.findme.wang/index.php?s=/Blog/detail/id/20.html)

okey了

仿CSND實現網頁中程式碼高亮顯示

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.