#3 Missing Line Breaks

SHJS
closed-fixed
nobody
SHJS (12)
5
2014-08-25
2008-08-16
No

SHJS strips <br/> tags from the text.

While they are not necessary within a <pre> tag, they're still allowed there. I encountered that problem when I integrated SHJS into phpBB3. phpBB3 automatically replaces all newlines in the post by <br/> tags.

The solution is quite simple, I only added two lines to the sh_getText() function in sh_main.js:

function sh_getText(element) {
// only works in some browsers
// if (element.nodeType === element.TEXT_NODE ||
// element.nodeType === element.CDATA_SECTION_NODE) {
if (element.nodeType === 3 ||
element.nodeType === 4) {
return element.data;
}
else if (element.nodeType === 1 && element.tagName === "BR" )
return "\r\n";
else if (element.childNodes.length === 1) {
return sh_getText(element.firstChild);
}
else {
var result = '';
for (var i = 0; i < element.childNodes.length; i++) {
result += sh_getText(element.childNodes.item(i));
}
return result;
}
}

Maybe this should be added to the next release so that it is possible to use SHJS with phpBB3 (and most other software that allows user-generated content).

Discussion

  • gnombat

    gnombat - 2008-08-16
    • status: open --> open-accepted
     
  • gnombat

    gnombat - 2008-08-18

    Logged In: YES
    user_id=1294975
    Originator: NO

    This should be fixed in version 0.5.

     
  • gnombat

    gnombat - 2008-08-18
    • status: open-accepted --> closed-fixed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks