• I use wordpress in my shop as a worklog tool for multiple technical systems engineer level users ( makes for nice reports when I can search the database for element category, date, author, etc). One thing that we have run across is the really pain-in-the-arse behavior of “<” and “>”. Even within <pre> tagsets, the content of html tags are trashed by the html protection code (I’m making an assumption there). For instance, the output of Solaris’ ‘ifconfig’ command is mangled, even when you put it through ‘pre’ tags.

    What I’ve done is hack the quicktags.js script to use <pre> rather than , and to change all instances of "<" or ">" to "&lt;" and "&gt;" in the selected text.

    In the IE section, I've done this:

    replaced<br>
    sel.text = edButtons[i].tagStart + sel.text + edButtons[i].tagEnd;
    with<br>

    if ( edButtons[i].display == "pre" ){
    var newtext = sel.text.replace(/</g,"&lt;");
    }
    if ( edButtons[i].display == "pre" ) {
    newtext = newtext.replace(/>/g,"&gt;");
    }
    sel.text = edButtons[i].tagStart + newtext + edButtons[i].tagEnd;

    Perhaps someone who's a better javascript coder than I can clean that up; I'm not sure why I had to use an exchange variable rather than $i=$i+mod type syntax. <br>
    The Moz/NS part was trickier for me (I've never written and javascript before, peeps, so go easy.. 🙂 ) I added:

    if (edButtons[i].display == "pre" ) {
    var newtext = myField.value.substring(startPos, endPos);
    var modtext = newtext.replace(/</g,"&gt;");
    modtext = modtext.replace(/>/g,"&lt;");
    }

    <br>right before:
    + myField.value.substring(startPos, endPos)
    <br> and changed:

    if (startPos != endPos) {
    myField.value = myField.value.substring(0, startPos)
    + edButtons[i].tagStart
    + myField.value.substring(startPos, endPos)
    + edButtons[i].tagEnd
    + myField.value.substring(endPos, myField.value.length);
    cursorPos += edButtons[i].tagStart.length + edButtons[i].tagEnd.length;
    }

    to say:<br>

    myField.value = myField.value.substring(0, startPos)
    + edButtons[i].tagStart
    // + myField.value.substring(startPos, endPos)
    + modtext
    + edButtons[i].tagEnd
    //+ myField.value.substring(endPos, myField.value.length);
    cursorPos += edButtons[i].tagStart.length + edButtons[i].tagEnd.length;
    }

    <br>
    All changes are in function edInsertTag(myField, i).

    Hope this is helpful to others; and I would be glad to hear from a real javascript coder on how to make this neater and why it didn't work the other way.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hacking quicktags.js’ is closed to new replies.