xheditor+ syntaxhighlighter外掛程式實現代碼高亮

來源:互聯網
上載者:User

一、準備工作是下載

這兩個外掛程式。


二、然後添加到你的項目中,然後在頁面中的匯入進去。某些版本還需匯入<SCRIPT src="js/shCoreCommon.js" type=text/javascript></SCRIPT>

<link type="text/css" rel="stylesheet" href="css/SyntaxHighlighter.css"></link><link href="css/prettify.css" rel="stylesheet" type="text/css" /><script  src="js/jquery-1.4.4.min.js" type="text/javascript"></script><script  src="js/xheditor-1.1.14-zh-cn.min.js" type="text/javascript"></script><script type="text/javascript" src="js/prettify/prettify.js"></script> <script type="text/javascript" src="js/ubb.min.js"></script><script type="text/javascript" src="js/Scripts/shCore.js"></script><script type="text/javascript" src="js/Scripts/shBrushCpp.js"></script><script type="text/javascript" src="js/Scripts/shBrushCSharp.js"></script><script type="text/javascript" src="js/Scripts/shBrushJava.js"></script><script type="text/javascript" src="js/Scripts/shBrushSql.js"></script><script type="text/javascript" src="js/Scripts/shBrushXml.js"></script><script type="text/javascript" src="js/Scripts/shBrushPhp.js"></script><script type="text/javascript" src="js/Scripts/shBrushJScript.js"></script><script type="text/javascript" src="js/Scripts/shBrushVb.js"></script><script language="javascript">window.onload = function () {    dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';    dp.SyntaxHighlighter.HighlightAll('code');}</script>
<script type="text/javascript">  $(pageInit);function pageInit(){var plugins={Code:{c:'btnCode',t:'插入代碼',h:1,e:function(){var _this=this;var htmlCode='<div><select id="xheCodeType"><option value="html">HTML/XML</option><option value="js">Javascript</option><option value="css">CSS</option><option value="php">PHP</option><option value="java">Java</option><option value="py">Python</option><option value="pl">Perl</option><option value="rb">Ruby</option><option value="c#">C#</option><option value="c">C++/C</option><option value="vb">VB/ASP</option><option value="">其它</option></select></div><div><textarea id="xheCodeValue" wrap="soft" spellcheck="false" style="width:300px;height:100px;" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="確定" /></div>';var jCode=$(htmlCode),jType=$('#xheCodeType',jCode),jValue=$('#xheCodeValue',jCode),jSave=$('#xheSave',jCode);jSave.click(function(){_this.loadBookmark();_this.pasteText('<pre name="code" class="'+jType.val()+'">'+jValue.val()+'</pre>');_this.hidePanel();return false;});_this.saveBookmark();_this.showDialog(jCode);}}};//這個是需要高亮代碼外掛程式的textarea的id$('#newContent').xheditor({plugins:plugins,tools:'full',showBlocktag:false,forcePtag:false,beforeSetSource:ubb2html,beforeGetSource:html2ubb,shortcuts:{'ctrl+enter':submitForm}});$('#replyContent').xheditor({plugins:plugins,tools:'full',showBlocktag:false,forcePtag:false,beforeSetSource:ubb2html,beforeGetSource:html2ubb,shortcuts:{'ctrl+enter':submitForm}});}function submitForm(){$('#solution').submit();}</script> 

<style type="text/css">.btnCode { background:url(images/code.gif) no-repeat 16px 16px; //這個url根據實際情況寫 background-position:2px 2px; } </style>




經過以上兩步實際效果就可以出來了~



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.