Answers.Body: <p>Don't use Redactor / a Rich Text field for code blocks is probably the only answer one can give right now.</p>
  
  <p>Instead you could use a Plain Text field for your article and get the formatting done with markdown. Or you could use Matrix and keep using Redactor for the text parts of your article and have a separate block type for code.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-23T02:08:23.967Z
Answers.Text: I prefer the markdown-enabled freetext field vs RichText anyway, good suggestion. I'd like to see the original problem solved down the track, though.
Answers.UserDisplayName: Marty
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-22T12:10:37.587Z
Answers.LastActivityDate: 2015-01-22T12:10:37.587Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>Im not sure if this is what you mean but you must encode the html you put inside the tag &lt;pre&gt;.</p>
  
  <p>A browser always render html code, so the only way is to encode the html to make it render as text.</p>
  
  <p>for example for &lt;p&gt; you have to write <code>&amp;lt;p&amp;gt;</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-22T11:20:46.977Z
Answers.Text: Of course, in fact the editor already does this for you. What I mean is that if I paste in some code that contains empty lines, they are stripped out.
Answers.UserDisplayName: Marty
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-22T13:18:58.883Z
Answers.Text: oh I understand now, 
  hmmm Im not sure at moment you can do what you want with Redactor.
  
  I agree with carlcs about his suggestion, then it depends if you have to use only for yourself or give it to users and how much is important have more consecutive empty lines.
Answers.UserDisplayName: Fabio Carriere
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-22T11:07:01.550Z
Answers.LastActivityDate: 2015-01-22T11:07:01.550Z
Answers.UserDisplayName: Fabio Carriere
Body: <p>I am using a RichText field type of my site content and I am inserting blocks of code within some <code>&lt;pre&gt;</code> tags which I add in the HTML view of the editor, however when I leave the HTML view, all of the empty lines within the <code>&lt;pre&gt;</code> block are stripped out.</p>
  
  <p>I've tried turning off the clean up HTML option etc with no luck. Is there a way to keep the empty lines (multiple consecutive newlines).</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-22T11:28:16.573Z
Comments.Text: I don't know what they mean with this bug-fix description in their [10.0.6 release notes](http://imperavi.com/redactor/log/): "'Pre'-wrapped HTML code of a webpage being rendered improperly", but maybe your problem has something to do with it? (Craft does not yet use this version.)
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-22T11:36:12.987Z
Comments.Text: Marty, do the already get removed after switching back and forth between HTML and WYSIWYG mode? Or does this happen on entry save?
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-22T11:37:31.623Z
Comments.Text: @carlcs When toggling back and forth between views. It remains OK on saving the entry.
Comments.UserDisplayName: Marty
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-22T11:46:03.190Z
Comments.Text: Ignore my first comment, tested the sample editor on  imperavi.com/redactor again and it shows your described behavior. If I then add the empty lines in WYSIWYG mode the HTML gets messed up with span tags `<span class="redactor-invisible-space">`!!
Comments.UserDisplayName: carlcs
Tags: <redactor><richtext>
Title: Retain empty lines in a RichText field
ThreadText: # Retain empty lines in a RichText field
  
  (Asked by: username_0 on 2015-01-22)
  
  I am using a RichText field type of my site content and I am inserting blocks of code within some `<pre>` tags which I add in the HTML view of the editor, however when I leave the HTML view, all of the empty lines within the `<pre>` block are stripped out.
  
  I've tried turning off the clean up HTML option etc with no luck. Is there a way to keep the empty lines (multiple consecutive newlines).
  
  **Tags:** redactor, richtext
  
  > **Comments:**
  > **username_1**: I don't know what they mean with this bug-fix description in their [10.0.6 release notes](http://imperavi.com/redactor/log/): "'Pre'-wrapped HTML code of a webpage being rendered improperly", but maybe your problem has something to do with it? (Craft does not yet use this version.)  
  > **username_1**: username_0, do the already get removed after switching back and forth between HTML and WYSIWYG mode? Or does this happen on entry save?  
  > **username_0**: @username_1 When toggling back and forth between views. It remains OK on saving the entry.  
  > **username_1**: Ignore my first comment, tested the sample editor on  imperavi.com/redactor again and it shows your described behavior. If I then add the empty lines in WYSIWYG mode the HTML gets messed up with span tags `<span class="redactor-invisible-space">`!!  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-01-22. Score: 4 | Accepted answer
  
  Don't use Redactor / a Rich Text field for code blocks is probably the only answer one can give right now.
  
  Instead you could use a Plain Text field for your article and get the formatting done with markdown. Or you could use Matrix and keep using Redactor for the text parts of your article and have a separate block type for code.
  
  > **Comments:**
  > **username_0**: I prefer the markdown-enabled freetext field vs RichText anyway, good suggestion. I'd like to see the original problem solved down the track, though.  
  
  ---
  
  ### Answer by username_2 on 2015-01-22. Score: 2
  
  Im not sure if this is what you mean but you must encode the html you put inside the tag <pre>.
  
  A browser always render html code, so the only way is to encode the html to make it render as text.
  
  for example for <p> you have to write `&lt;p&gt;`
  
  > **Comments:**
  > **username_0**: Of course, in fact the editor already does this for you. What I mean is that if I paste in some code that contains empty lines, they are stripped out.  
  > **username_2**: oh I understand now,  hmmm Im not sure at moment you can do what you want with Redactor.  I agree with username_1 about his suggestion, then it depends if you have to use only for yourself or give it to users and how much is important have more consecutive empty lines.  
  
  ---
  
  