if(isIE){ getEl("prevDiv").innerHTML="<div>"+getEl("comment").value.replace(/(\n|\r)/g,'<br/>').replace(/(<br\/><br\/>)/g,'<br/>')+"</div>" }
else{ getEl("prevDiv").innerHTML="<div>"+getEl("comment").value.replace(/(\n|\r)/g,'<br>')+"</div>" }
Something like this:
html="<div>"+getEl("comment").value.replace(/(\n|\r)/g,'<br>').replace(/<\s*img[^>]+>/gi, "[IMG tag disabled]");
getEl("prevDiv").innerHTML = isIE ? html.replace(/(<br\/><br\/>)/g,'<br/>') : html;
This is far from bulletproof in that it does tag replacement with a RE but it doesn't matter too much since it's just for preview, the real filtering is still done server-side.<IMG SRC="http://goatse.cx/hello.jpg" title="gaping asshole">turns into
<div class="image">with a little bit of differentiating style applied to the image class in the css. In the absence of a title tag, the link text would be the image URL. Having them in their own div would make it super retardedly easy to do inlining in greasemonkey.
<IMG SRC="http://metafilter.com/littleImageIcon.png">
<a href="http://goatse.cx/hello.jpg">gaping asshole</a>
</div>
posted by econous at 4:29 PM on November 18, 2006