-
1. Re: Show HTML content from rich:editor
mcmurdosound Oct 14, 2011 9:24 AM (in response to satyakatti)I have used a disabled version of the rich:editor which also hides the toolbar in this state.
<rich:editor id="myid"
value="..."
theme="simple"
readonly="#{readonly}"
oninit="if (#{readonly}) jQuery("#myid").find('.mceToolbar.mceLast').hide();"/>
-
2. Re: Show HTML content from rich:editor
satyakatti Oct 14, 2011 9:50 AM (in response to mcmurdosound)I had to use h:outputText like this : <h:outputText value="#{testplannerBean.description}" escape="false"></h:outputText>
which escapes the content sensitive to HTML
-
3. Re: Show HTML content from rich:editor
mcmurdosound Oct 14, 2011 9:53 AM (in response to satyakatti)1 of 1 people found this helpfulWarning: Please try to insert javascript-code into your rich:editor. Like: <script>alert('hello world');</script>
No unescaped html code from userinput should be written into your documents!
-
4. Re: Show HTML content from rich:editor
satyakatti Oct 14, 2011 10:29 AM (in response to mcmurdosound) -
5. Re: Show HTML content from rich:editor
mcmurdosound Oct 17, 2011 1:54 AM (in response to satyakatti)One other thing: if somebody tries to copy and paste code from a microsoft office application into your rich:editor, you'll get ugly xml code. In my case I had to cleanup the code first right after completing the copy and paste event.
/* copy and paste from m$office:
*/
function cleanWord(str){
// get rid of unnecessary tag spans (comments and title)
if (typeof str === 'undefined') return "";
str = str.replace(/\<\!--(\w|\W)+?--\>/gim, '');
str = str.replace(/\<title\>(\w|\W)+?\<\/title\>/gim, '');
// Get rid of classes and styles
str = str.replace(/\s?class=\w+/gim, '');
str = str.replace(/\s+style=\'[^\']+\'/gim, '');
// Get rid of unnecessary tags
str = str.replace(/<(meta|link|\/?o:|\/?style|\/?div|\/?st\d|\/?head|\/?html|body|\/?body|\/?span|!\[)[^>]*?>/gim, '');
// Get rid of empty paragraph tags
str = str.replace(/(<[^>]+>)+ (<\/\w+>)/gim, '');
// remove bizarre v: element attached to <img> tag
str = str.replace(/\s+v:\w+=""[^""]+""/gim, '');
// remove extra lines
str = str.replace(/"(\n\r){2,}/gim, '');
// Fix entites
str = str.replace("“", "\"");
str = str.replace("”", "\"");
str = str.replace("—", "–");
return str;
}
function cleanStuff(id){
var h = jquery(id).find('iframe').contents().find('body[id=tinymce]').html();
if (typeof h === 'undefined') return;
jquery(id).find('iframe').contents().find('body[id=tinymce]').html(cleanWord(h));
}
function setupPaste(id){
//console.log("setupPaste " + id);
jquery(id).find('iframe').contents().bind('paste', function(e){
setTimeout(function(){cleanStuff(id);}, 100);
});
}
the "setupPaste(id)" function is bound to the rich editor at its "oninit=..." attribute.