Automatic line break in js SyntaxHighlighter

Eric Herlitz picture Eric Herlitz · Jun 9, 2011 · Viewed 9.5k times · Source

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 Horizontal scrollbar

Anyone out there who know the way around this?

Answer

kevinji picture kevinji · Jun 9, 2011

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;
}