0

We are using Tridion 2011 SP1. After publishing the page source of the page is getting distorted. Javascript and other HTMl sections are coming on same line it seems that it is ignoring new line charater but if we copy paste page source to Notepad++ alignment is looking good but in page source it is shown destorted. Even in the page preview source is coming properly. What can be done to fix this.

user1453602
  • 1,165
  • 5
  • 14
  • 5
    I'm sorry, but how critical is this? Is any functionality broken? If you see the source correctly in Notepad++ it suggests that you may be using unix-style line breaks instead of Windows-style. Which browsers have you used to check the source? – Nuno Linhares Feb 04 '13 at 13:46
  • furthermore - it is a good idea to actually strip out all the white-space on the page to improve page load performance. Rather than putting it back in, you might consider running a minifier to actually strip more of it out. – Chris Summers Feb 04 '13 at 14:03

2 Answers2

2

By default tridion uses just a linefeed to indicate end of line but most Windows applications expect the end of line markers to be carriage return-linefeed and will show text with just linefeeds as having just one line.

You can modify your publishing code so one of the final steps in the rendering process is to append a carriage return right before all the linefeeds that don't already have a carriage return before them and then the page source won't appear 'distorted'

One thing to note is this shouldn't be having any impact on the way the page is rendered to the end-user.

Glenn Stevens
  • 1,998
  • 13
  • 21
2

Firstly, as others have already pointed out, this should be completely unnecessary and have absolutely no effect on the proper functioning of your web site. It is purely superficial. Indeed, as Chris mentioned, many developers strive to 'minify' their code as much as possible in order to reduce amount of bits going down the wire to users.

However, should you really need your Windows style line endings, the following .Net TBB should help. Be sure to run it after you have produced your output.

using Tridion.ContentManager.Templating;
using Tridion.ContentManager.Templating.Assembly;

namespace SDLTridion.Bootstrap.Templating
{
    [TcmTemplateTitle("Enforce Windows Line Ending")]
    public class EnforceWindowsLineEnding : ITemplate
    {
        public void Transform(Engine engine, Package package)
        {
            Item outputItem = package.GetByName(Package.OutputName);
            string outputContent = outputItem.GetAsString();
            outputContent = outputContent.Replace("\r", "\r\n");
            outputItem.SetAsString(outputContent);
        }
    }
}
David Forster
  • 1,390
  • 9
  • 16