August 12, 2003

The “Convert Line Breaks” text filter inserts a <br /> tag for every end-of-line character inside a paragraph. This causes problems if your entry has HTML tags that internally contain end-of-line characters (often complicated links that you copy from somewhere else contain end-of-line characters).

This hack fixes the formatting function to ignore end-of-line characters inside of HTML tags. Note that it may slow down the rebuilding of your pages a little!

lib/MT/Util.pm Modification

Go to your MovableType installation directory, and open the file Util.pm in the lib/MT subdirectory.
  1. In the function html_text_transform, find the line that says:
                $p =~ s!\r?\n!<br />\n!g;
    
    and replace it with the following code:
    ## BEGIN HACK Multiline Tags with "Convert Line Breaks"
    ## http://www.nonplus.net/software/mt/MultilineTagswithConvertLineBreaks.htm
                $p = join '', grep { s!\r?\n!<br />\n!g unless /^</; 1; } split /(<.*?>)/s, $p;
    ## END HACK Multiline Tags with "Convert Line Breaks"