Discuz7使用syntaxhighlighter_2.0.320实现代码高亮
Discuz7使用syntaxhighlighter_2.0.320實現代碼高亮
一、修改./templates/default/discuzcode.htm文件
在function tpl_codedisp($discuzcodes, $code) 函數前增加如下函數
function tpl_codecsh($discuzcodes, $code, $lang) {
}–>
<!–{block return}–><code id="code$discuzcodes[codecount]"><pre class="brush: $lang">$code</pre></code><!–{/block}–>
<!–{eval return $return;}–>
<!–{eval
}
二、修改./templates/你的風格/header.htm
在</head>前添加:
<link href="plugins/syntaxhighlighter/styles/shCore.css" type="text/css" rel="stylesheet" />
<link href="plugins/syntaxhighlighter/styles/shThemeDefault.css" type="text/css" rel="stylesheet" />
<script src="plugins/syntaxhighlighter/src/shCore.js" type="text/javascript"></script>
<script class="javascript">
?SyntaxHighlighter.config.clipboardSwf = 'plugins/syntaxhighlighter/scripts/clipboard.swf';
</script>
三、修改./templates/你的風格/footer.htm
在</body>前添加:
<script class="javascript" src="plugins/syntaxhighlighter/src/shCore.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushAS3.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushBash.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushCpp.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushCSharp.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushCss.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushDelphi.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushDiff.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushGroovy.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushJava.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushJavaFX.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushJScript.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushPerl.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushPhp.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushPlain.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushPowerShell.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushPython.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushRuby.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushScala.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushSql.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushVb.js"></script>
<script class="javascript" src="plugins/syntaxhighlighter/scripts/shBrushXml.js"></script>
<script class="javascript">
?SyntaxHighlighter.config.clipboardSwf = 'plugins/syntaxhighlighter/scripts/clipboard.swf';
?SyntaxHighlighter.config.stripBrs=true;
?SyntaxHighlighter.all();
</script>
四、修改./include/discuzcode.func.php
在function codedisp($code)函數下面添加如下函數
function codedpdisp($code, $lang) {
?global $discuzcodes;
?$discuzcodes['pcodecount']++;
?$code = htmlspecialchars(str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code)));
?$discuzcodes['codehtml'][$discuzcodes['pcodecount']] = tpl_codecsh($discuzcodes, $code, $lang);
?$discuzcodes['codecount']++;
?return "[\tDISCUZ_CODE_$discuzcodes[pcodecount]\t]";
}
在$message = preg_replace("/\s*\[code\](.+?)\[\/code\]\s*/ies", "codedisp('\\1')", $message);上面增加如下代碼
$message = preg_replace("/\s*\[code=\"(xml|xhtml|xslt|html|vb|vbnet|sql|scala|ruby|rails|ror|powershell|ps|text|plain|php|py|python|perl|Perl|pl|js|jscript|javascript|jfx|javafx|groovy|java|diff|patch|delphi|pascal|css|c#|c-sharp|csharp|cpp|c|bash|shell|actionscript3|as3){1}\"\](.+?)\[\/code\]\s*/ies", "codedpdisp('\\2', '\\1')", $message);
把return $htmlon ? $message : nl2br(str_replace(array("\t", '?? ', '? '), array(' ', ' ', ' '), $message));替換為
$message = $htmlon ? $message : nl2br(str_replace(array("\t", '?? ', '? '), array(' ', ' ', ' '), $message));
??? for($i = 0; $i <= $discuzcodes['pcodecount']; $i++) {
??????? $message = str_replace("[\tDISCUZ_CODE_$i\t]", $discuzcodes['codehtml'][$i], $message);
}
??? return $message;
五、修改./include/js/post.js
在</textarea>';下面增加如下代碼
if (cmd == 'code') {
??????????????? str += '<br />請選擇語言: <select id="' + ctrlid + '_param_2">'
?????+ '<option value="">-=程序語言=-</option>'
??????????????????? + '<option value="php">PHP</option>'
??????????????????? + '<option value="css">CSS</option>'
??????????????????? + '<option value="xhtml">XML/XHTML</option>'
??????????????????? + '<option value="javascript">Javascript</option>'
??????????????????? + '<option value="sql">SQL</option>'
??????????????????? + '<option value="csharp">C#</option>'
??????????????????? + '<option value="java">Java</option>'
??????????????????? + '<option value="cpp">C/C++</option>'
??????????????????? + '</select>';
??????????? }
別的語言根據需要和上面的列表進行添加
在
if(wysiwyg) {
??? if(cmd == 'code') {
???? text = preg_replace(['<', '>'], ['<', '>'], text);
??? }
??? text = text.replace(/\r?\n/g, '<br />');
?? }下面增加如下代碼
if (cmd == 'code' && $(ctrlid + '_param_2').value != '') {
??????????????? opentag = '[code="' + $(ctrlid + '_param_2').value + '"]';
??????????????? text = "\n" + text + "\n";
??????????? }
六、如果需要漢化修改./plugins/syntaxhighlighter/src/shCore.js相關數據并根據論壇的編碼修改成相對應的編碼。
七、效果圖(下載地址http://download.csdn.net/source/1547749)
?
轉載于:https://www.cnblogs.com/wkjs/archive/2009/08/05/2008435.html
總結
以上是生活随笔為你收集整理的Discuz7使用syntaxhighlighter_2.0.320实现代码高亮的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: .NET : 再谈谈多线程
- 下一篇: oracle 表分区[三]