Can I convert rich text field to have plain text output - with carriage returns? I am exporting some fields to an XML feed. There is a rich text field with typically 4 paragraphs in it.

The default export kicks out:

&lt;p&gt;Some text&lt;/p&gt; tags as well as stuff like &lt;strong&gt;.


This is easy to remove with |striptags.

However, this results in text that doesn't have proper spacing and removes any intended carriage returns.

I can fix the spacing with a

|replace(".", ". ")


But I'd rather have the the Paragraphs to still have carriage returns as intended. I know I can add in the right UTF-8 symbol, but I don't want this in the data, I just want the spacing and carriage returns as if it were a plain text field and not to have the UTF-8 symbols in the feed itself.

http://www.fileformat.info/info/unicode/char/000D/index.htm

Any help, much appreciated.
Completely untested, but you should be able to do use something like the Craft-TwigPCRE plugin and some variation of this code:

{% set text = "&lt;p&gt;Some text&lt;/p&gt; tags as well as stuff like &lt;strong&gt;.|preg_replace('/\&lt;p\&gt;/', '') %}

{% set text = text|preg_replace('/\&lt;\/p\&gt;/', '\\n') %}


\n is the Line Feed control character for Unix/OSX.