To clarify on the title a bit more, this is for a plugin for my forum.
I’m doing this:
div.html( parser( div.html() ) )
When sending the html string to the parser, of course I get something like:
"[BBC][/BBC]n<code>[BBC][/BBC]</code>"
What’s the best method I could use to prevent the parsing of the BBC tag inside the code tag?
6
A workaround would be to save each code block before the plugin parses the post, then restore the blocks afterwards.
EDIT:
So I’ve changed things around and am working on a slightly more efficient method rather than text replacement (mentioned in the OP), which will still be considered here.
Here’s what I’m using now:
function parse( node ) {
// backup code blocks
var codes = []; node.find('code').each(function() { codes.push($(this).html()); });
// Do whatever you need to here
// restore the code blocks
var i=0; node.find('code').each(function() { $(this).html(codes[i]); i = i+1; });
};
^ applies the changes to the element directly
For the old method mentioned in the OP:
function parse( post ) {
var node = $('<div>'+post+'</div>');
// backup the code blocks
var codes = []; node.find('code').each(function() { codes.push($(this).html()); });
post = ''; // <-- Do whatever you need to here
node.html( post ); // update the node
// restore the code blocks
var i=0; node.find('code').each(function() { $(this).html(codes[i]); i = i+1; });
return node.html();
};
I don’t recommend this method, it’s just a workaround until I’m able to just ignore code blocks altogether.
2