2

We are having an RTF field and Editors would be pasting small html snippets in it. Finally we are generating Json output using Newtonsoft json (Json.net) Serializer. Strangely I have come across an issue where our json is having \r\n in it. I have tried editing the html in RTF field not to contain any line breaks but somehow Tridion is formatting it back.

Input in RTF Field:

<center><strong>First Line</strong></center><center>Second Line</center><center>Third Line</center>

After Clicking of design or preview Tab of RTF field:

<center><strong>First Line</strong></center>
<center>Second Line</center>
<center>Third Line</center>

Final Json output:

"test":"<center><strong>First Line</strong></center>\r\n<center>Second Line</center>\r\n<center>Third Line</center>"

Is my understanding correct that Tridion is inserting line breaks or new line after closing of each html tag and hence the serializer is representing it as \r\n? Or is there something wrong?

  • Tridion, out of the box, would not place "\r\n" at the line breaks, to my knowledge. It should be your component template that is performing this rendition or your filtering XSLT associated with your RTF. You can test this by associating your schema with the default component template and preview it in the CME as well. Cheers. – Shiva Jan 12 '17 at 17:06
  • No luck as changing XSLT isn't solving the issue. – Guest19876 Jan 13 '17 at 9:43
2

You're correct... This will be caused by a combination of two things:

  1. Tridion runs Tidy over RTF fields, which is what's adding the line breaks after you click on the design or preview tab after entering source code.

  2. The JSON serializer is seeing those line breaks and encoding them as \r\n (as per the JSON spec).

I don't think NewtonSoft.Json allows control of how it encodes control characters (i.e. the carriage returns and new lines that you're seeing). If you can, I would advise simply removing any line breaks from the field values either before or after serialization, as I think this will be simpler than trying to control the "built-in" version of Tidy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.