<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>

CC BY-SA 3.0
2015-01-23T02:08:23.967Z
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.
Marty
CC BY-SA 3.0
2015-01-22T12:10:37.587Z
2015-01-22T12:10:37.587Z
carlcs
<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>

CC BY-SA 3.0
2015-01-22T11:20:46.977Z
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.
Marty
CC BY-SA 3.0
2015-01-22T13:18:58.883Z
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.
Fabio Carriere
CC BY-SA 3.0
2015-01-22T11:07:01.550Z
2015-01-22T11:07:01.550Z
Fabio Carriere
<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>

CC BY-SA 3.0
2015-01-22T11:28:16.573Z
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.)
carlcs
CC BY-SA 3.0
2015-01-22T11:36:12.987Z
Marty, do the already get removed after switching back and forth between HTML and WYSIWYG mode? Or does this happen on entry save?
carlcs
CC BY-SA 3.0
2015-01-22T11:37:31.623Z
@carlcs When toggling back and forth between views. It remains OK on saving the entry.
Marty
CC BY-SA 3.0
2015-01-22T11:46:03.190Z
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">`!!
carlcs
<redactor><richtext>
Retain empty lines in a RichText field
# 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  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  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 .
A browser always render html code, so the only way is to encode the html to make it render as text.
for example for  you have to write <p>

> **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.  

---

