PDA

View Full Version : HtmlEditor <pre></pre>



davidryan
15 Feb 2013, 10:29 AM
I'm trying to get pre blocks working in the htmleditor component. I must be doing something retarded, but the following regex should match everything wrapped within the pre block:


var preText = html.match( /<pre[\s\S]<\/pre>/igm);


However preText is null, and the <pre> tags are present (i.e. I'm doing this as part of the cleanHtml function in the htmleditor).

Any suggestions?

davidryan
16 Feb 2013, 2:52 AM
Here's exactly what I am doing, which is not returning a match when cleanHtml is invoked (e.g. switch between preview/code):



html = html.replace(/<pre>([\s\S]*)<\/pre>/i, function(v) {console.log(v)});


My plan is to htmlEncode the capture group and return it for replacement.

I know this section is being called and is working, as I am already handling another condition.

davidryan
17 Feb 2013, 7:33 AM
I was not handling the capture group correctly.

In my case, the following worked (if anyone needs to do something similar):



var preRegex = /<pre>([\s\S]*?)<\/pre>/im;
html = html.replace(preRegex, function(v) {
var content = preRegex.exec(v);
console.log(content[1]);
return '<pre>'+Ext.util.Format.htmlEncode(content[1])+'</pre>';
});


Doing this as part of "cleanHtml" was obviously not a good idea, as it gets called each time the cleanHtml function runs. I have added a function to insert the pre blocks into the htmleditor field. There might be better ways of handling this, so if anyone has any suggestions please feel free to reply.