TinyMCE, for some reason, likes to convert to and from newline characters '\n' into <br/>. This has the undesired effect of breaking formatting within <pre> tags, which is very annoying if you use them to wrap around source code.
The solution, with a small cleanup plugin:
fixNewLines = function(type, content)
{
switch (type) {
case "get_from_editor":
content = content.replace(/<br\s*\/>/gi, "\n");
break;
case "insert_to_editor":
break;
}
return content;
}
In order to have the plugin loaded, add the following to the code that creates the TinyMCE editor:
tinyMCE.init({
...
cleanup_callback: fixNewLines,
...
});
Just make sure that the cleanup plugin is loaded before the TinyMCE object is instantiated.
This idea isn't mine, I only improved the regexp, but I cannot find the link where I saw it...