z-blog SyntaxHighlighter 长代码无法换行解决办法(jquery)
2014-11-16 23:25
666 查看
由于我的博客主要是代码分享,很多贴的代码,都很长。很多时候我都是手动给他换行。
但是今天实在是受不了。从网上找个办法解决一下。
1、css修改:
在文件夹:\zb_system\ADMIN\ueditor\third-party\SyntaxHighlighter
在文件shCoreDefault.pack.css添加css:
复制代码 代码如下:body .syntaxhighlighter .line{ white-space: pre-wrap !important;} .syntaxhighlighter{width:100%!important;margin:.3em 0 .3em 0!important;position:relative!important;overflow:auto!important;background-color:#f5f5f5!important;border:1px solid #ccc!important;word-break:break-all;
2、Jquery代码:
$(function () { // Line wrap back var shLineWrap = function () { $('.syntaxhighlighter').each(function () { // Fetch var $sh = $(this), $gutter = $sh.find('td.gutter'), $code = $sh.find('td.code') ; // Cycle through lines $gutter.children('.line').each(function (i) { // Fetch var $gutterLine = $(this), $codeLine = $code.find('.line:nth-child(' + (i + 1) + ')') ; //alert($gutterLine); // Fetch height var height = $codeLine.height() || 0; if (!height) { height = 'auto'; } else { height = height += 'px'; //alert(height); } // Copy height over $gutterLine.attr('<SPAN style="WIDTH: auto; HEIGHT: auto; float: none" id=0_nwp><A style="TEXT-DECORATION: none" id=0_nwl href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Esuchso%2Ecom%2Fprojecteactual%2Fz%2Dblog%2Djquery%2DSyntaxHighlighter%2Dlongcode%2Ehtml&p=baidu&c=news&n=10&t=tpclicked3_hc&q=95053049_cpr&k=style&k0=%CE%C4%BC%FE%BC%D0&kdi0=32&k1=style&kdi1=1&k2=%B2%A9%BF%CD&kdi2=1&sid=77860fedb9413425&ch=0&tu=u1702844&jk=e7459084404b7b2f&cf=29&fv=15&stid=9&urlid=0&luki=2&seller_id=1&di=128" target=_blank mpid="0"><SPAN style="WIDTH: auto; FLOAT: none; HEIGHT: auto; COLOR: #0000ff; FONT-SIZE: 16px">style</SPAN></A></SPAN>', 'height: ' + height + ' !important'); // fix by Edi, for JQuery 1.7+ under Firefox 15.0 console.debug($gutterLine.height(), height, $gutterLine.text(), $codeLine); }); }); }; // Line wrap back when syntax highlighter has done it's stuff var shLineWrapWhenReady = function () { if ($('.syntaxhighlighter').length === 0) { setTimeout(shLineWrapWhenReady, 10); } else { shLineWrap(); } }; // Fire shLineWrapWhenReady();});
上面的代码就是属于长代码。大家看看是不是都换行了??
现在,行号的高度就能和代码的高度保持一致了。
您可能感兴趣的文章:
相关文章推荐
- z-blog SyntaxHighlighter 长代码无法换行解决办法(jquery)
- z-blog SyntaxHighlighter 长代码无法换行解决办法(基于jquery)
- z-blog SyntaxHighlighter 长代码无法换行解决办法(基于jquery)
- VC2005:无法执行添加/移除操作,因为代码元素是只读的....多个解决办法
- 添加Service Reference, 无法为服务生成代码错误的解决办法
- 添加Service Reference, 无法为服务生成代码错误的解决办法
- JS、jqueryie6浏览器下使用js无法提交表单的解决办法
- 添加Service Reference, 无法为服务生成代码错误的解决办法
- windows 7 防火墙无法开启!错误代码5 错误代码0x6D9 解决办法
- div中英文无法自动换行的解决办法
- jquerymobile changepage 无法加载外部js文件解决办法
- 禁用Resharper长代码自动换行的解决办法
- SVN 无法连接服务器 不能查看日志 不能提交的代码 解决办法
- label自动换行代码和DataGrid中删除最后一页的记录时出错的解决办法以及HTML小TIPS:强制HTML表格断行
- VC2005:无法执行添加/移除操作,因为代码元素是只读的....多个解决办法
- 关于textarea提交的内容无法换行的解决办法
- jQuery.Syntax-我blog用的代码高亮插件
- ImageButton 放到 datalist中,cs代码中无法识别的解决办法
- 无法执行添加/移除操作,因为代码元素是只读的....多个解决办法
- label自动换行代码和DataGrid中删除最后一页的记录时出错的解决办法以及HTML小TIPS:强制HTML表格断行