syntaxhighlighter4 长代码自动换行

SyntaxHighlighter 是一款代码高亮插件

github address

markdown 语法html标签
``` java
hello, markdown
```
<pre class="brush:java">
hello, markdown
</pre>
  • 修改如下:

1.syntaxhighlighter4\dist\theme-default.css

  .syntaxhighlighter .line {  
    white-space: pre !important; }

修改为

  .syntaxhighlighter .line {
    white-space: pre-wrap !important; }

2.增加js

<script type="text/javascript">
    //jquery 3.3.1 写法$(window).on('load',function(){})
    //jquery 1.8 可以$(window).load(function(){})
    $(window).on('load',function(){
        $('.code .line').each(function(index){
            var yqhg=$(this).height();
            $('.gutter .line:eq('+index+')').attr('style','height:'+yqhg+'px !important')
        });
    });
    //<pre>代码行数 随browser窗口变化而变化
    $(window).resize(function () {
        $('.code .line').each(function(index){
            var yqhg=$(this).height();
            $('.gutter .line:eq('+index+')').attr('style','height:'+yqhg+'px !important')
        });
    });

</script>