作者: whooyun发表于: 2017-03-31 00:57
html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code)'</pre>';
改为以下的内容:
//html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) +'</pre>'; //将代码高亮替换为SyntaxHighlighter插件需要的类名 html = '<pre class="brush:' + type + ';">\n' + K.escape(code) +'</pre>'; //此处为将原有写法注释,上一行为修改后的内容。
2、修改kindeditor自带的代码插入(code.js文件),替换其中的select就可以了
'<select class="ke-code-type">', '<option value="java">Java</option>', '<option value="php">PHP</option>', '<option value="html">HTML</option>', '<option value="css">CSS</option>', '<option value="js">JavaScript</option>', '<option value="xml">XML</option>', '<option value="shell">Shell</option>', '<option value="sql">SQL</option>', '</select>',3、在文章展示页面加入css,js
<link rel="stylesheet" href="<%=path%>/static/js/syntaxhighlighter_3.0.83/styles/shCore.css" media="screen" /> <link rel="stylesheet" href="<%=path%>/static/js/syntaxhighlighter_3.0.83/styles/shThemeDefault.css" media="screen"/> <script type="text/javascript" src="<%=path%>/static/js/syntaxhighlighter_3.0.83/scripts/shCore.js"></script> <script type="text/javascript" src="<%=path%>/static/js/syntaxhighlighter_3.0.83/scripts/shBrushJava.js"></script> <script type="text/javascript" src="<%=path%>/static/js/syntaxhighlighter_3.0.83/scripts/shBrushCss.js"></script> <script type="text/javascript" src="<%=path%>/static/js/syntaxhighlighter_3.0.83/scripts/shBrushJScript.js"></script> <script type="text/javascript" src="<%=path%>/static/js/syntaxhighlighter_3.0.83/scripts/shBrushPython.js"></script> <script type="text/javascript" src="<%=path%>/static/js/syntaxhighlighter_3.0.83/scripts/shBrushSql.js"></script> <script type="text/javascript" src="<%=path%>/static/js/syntaxhighlighter_3.0.83/scripts/shBrushXml.js"></script> <script type="text/javascript"> $(document).ready(function(){ SyntaxHighlighter.all(); }) </script>注意:样式引入,你需要支持哪些变成语言就引用哪些就好了,其余的可以不引用,我使用type="text/css",一直没法正常展示,所以我改成了rel="stylesheet",然后一切就正常了,另外由于引入js太多,页面展示比较慢,建议用下面这种方法
<link type="text/css" href="syntax/shCore.css" media="screen" /> <link type="text/css" href="syntax/shThemeDefault.css" media="screen"/> <script type="text/javascript" src="syntax/shCore.js"></script> <script type="text/javascript" src="syntax/shAutoloader.js"></script> <script type="text/javascript"> $(document).ready(function(){ SyntaxHighlighter.autoloader( 'java /syntax/shBrushJava.js', 'php /syntax/shBrushPhp.js', 'html xml /syntax/shBrushXml.js', 'css /syntax/shBrushCss.js', 'js jscript javascript /syntax/shBrushJScript.js', 'bash shell /syntax/shBrushBash.js', 'sql /syntax/shBrushSql.js' ); SyntaxHighlighter.all(); }); </script>插件下载地址:syntaxhighlighter下载