Well, I only have a partial answer, but it can still help you a little. From what I'm going to, you would like to enter or paste some code into the tinyMCE text area (and not into the HTML source code of the editor field), and then apply some styles to this block afterwards, so that it will be prettified.
(As a side element, I think that anyone who qualifies adding a code block to a richt text editor field should be able to click the "raw html" button, paste its code and wrap it in <pre> or <code> especially if you add a little instructions on what to do, just above or below the editor area. And then you will be free at home. And everyone does it like that.)
However, returning to the original problem. If you enter lines of code in the tinyMCE text area, each time you click on it, you will get your own string wrapped in a <p> .
So, if you type:
if (this_is_the_best_line_ever == true) { ... }
and press enter, you will get
<p>if (this_is_the_best_line_ever == true) { ... }</p>
So, using your example, you would never see this
<code class="prettyprint"> codeline1 codeline2 codeline3 </code>
but rather it
<code class="prettyprint"> <p>codeline1</p> <p>codeline2</p> <p>codeline3</p> </code>
The problem with the latter is that it is invalid HTML, never was, never will be, and tinyMCE will rightfully not create this code. The reason <pre> and <code> are inline elements, and <p> is a block level element, so <pre> and <code> cannot contain any <p> s.
We get an answer (even if it's only half the answer), so don't give up.
A better approach is to use <div> wrappers around your code block. This is legal, tinyMCE will happily do it for you, see below (note the wrapper attribute!):
style_formats : [ {title : 'Codigo fuente', block : 'div', classes : 'prettyprint', wrapper: 1} ]
We could start celebrating right now, but your chosen plugin, the code prefix, only processes the <pre> and <code> tags from your html, so unfortunately these blocked <div> blocks of code would not be good, oh so beautiful...
You can a) hack the prettify plugin and make it learn div tags that have specific classes, or b) make tinyMCE forget about these <p> wrappers.
Now, moving on to the second parameter, you can initialize tinyMCE with the following parameters:
forced_root_block : false, force_br_newlines : true, force_p_newlines : false
and your lines will be separated by <br> tags instead of wrapped <p> tags. This greatly discourages tinyMCE authors for various reasons (see the FAQ ), but it is still a valid option.
Now you can trick tinyMCE to wrap all the content in a <code> block with the following configuration (which hacks a bit on its own, but works, basically ahem):
style_formats : [ {title : 'Codigo fuente', block : 'code', classes : 'prettyprint', wrapper: 1} ]
Your only problem with applying this style will remove existing <br> tags from your text. That's right, you will have all the code you have selected in one line. And I tried many ways to keep these tiny little pathetic tags <br> , but couldn't chase tinyMCE to do this. It was here that I gave up, hence the “half answer”. Good luck