Menu

#12 Allow wrap

open
nobody
None
5
2008-12-24
2008-12-24
c c
No

The following are directions to add line wrapping functionality to version 0.9.6.

Add these to the bottom of codepress.css:
.wrap>pre{
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}

Replace lines 79-81 of codepress.js
self.toggleLineNumbers = function() {
var cn = self.editor.body.className;
self.editor.body.className = (cn==''||cn=='show-line-numbers') ? 'hide-line-numbers' : 'show-line-numbers';
}

with the following:
self.toggleLineNumbers = function() {
var b=self.editor.body, c=b.className;
b.className=(c.match('hide-line-numbers'))?c.replace(/hide-line-numbers/g,''):c+' hide-line-numbers';
}

self.toggleWrap = function(){
var b=self.editor.body, c=b.className;
b.className=(c.match('wrap'))?c.replace(/wrap/g,''):c+' wrap';
}

Finally, to allow preloading on line 58 of codepress.js, below
if(self.options.match('linenumbers-off')) self.toggleLineNumbers();
add this:
if(self.options.match('wrap')) self.toggleWrap();

To enable wrapping either add the "wrap" class to the textarea you are replacing or call "codepress_id.toggleWrap();".

Discussion

  • c c

    c c - 2009-01-06

    Edited files for this patch.

     
  • c c

    c c - 2009-01-06

    Use this on line 58 instead. The regex is more precise here.

    self.toggleLineNumbers = function() {
    var b=self.editor.body, c=b.className;
    b.className=(c.match(/\bhide-line-numbers\b/))?c.replace(/\bhide-line-numbers\b/g,''):c+' hide-line-numbers';
    }

    self.toggleWrap = function(){
    var b=self.editor.body, c=b.className;
    b.className=(c.match(/\bwrap\b/))?c.replace(/\bwrap\b/g,''):c+' wrap';
    }

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.