且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

js SyntaxHighlighter中的自动换行符

更新时间:2022-12-27 16:30:57

我实际上并没有使用SyntaxHighlight,但似乎可以附加一个空格:pre-wrap CSS样式到< pre> < script> 标签,SyntaxHighlight使用。



HTML(使用< pre> ):

 < pre class =brush:jsclass =syntaxhighlight> 
/ **
* SyntaxHighlighter
* /
function foo()
{
if(counter< = 10)
return;
//它有效!
}
< / pre>

HTML(使用< script> ) :

 < script type =syntaxhighlighterclass =syntaxhighlight brush:js><![CDATA [
/ **
* SyntaxHighlighter
* /
函数foo()
{
if(counter< = 10)
return;
//它有效!
}
]]>< / script>

CSS:

  .syntaxhighlight {
white-space:pre-wrap;
}


Im using the js SyntaxHighlighter 3.0.83 from http://alexgorbatchev.com/SyntaxHighlighter/

I've been googling the entire world now it seem but cant really find how to enable line breaks. Instad i get a horizontal scrollbar, which is good sometimes but not in my scenario.

In example

Anyone out there who know the way around this?

I don't actually use SyntaxHighlight, but it seems to be possible to attach an white-space: pre-wrap CSS style to the <pre> or <script> tag that SyntaxHighlight uses.

HTML (using <pre>):

<pre class="brush: js" class="syntaxhighlight">
    /**
     * SyntaxHighlighter
     */
    function foo()
    {
        if (counter <= 10)
            return;
        // it works!
    }
</pre>

HTML (using <script>):

<script type="syntaxhighlighter" class="syntaxhighlight brush: js"><![CDATA[
    /**
     * SyntaxHighlighter
     */
    function foo()
    {
        if (counter <= 10)
            return;
        // it works!
    }
]]></script>

CSS:

.syntaxhighlight {
    white-space: pre-wrap;
}