Menu

#257 BR within PRE rendered with additional linefeeds

open
nobody
5
2012-10-08
2012-06-07
No

Sometimes in the wild there is HTML code with PRE sections containing BR tags instead of linefeeds, like so:

first line
second line
third line

JTidy's pretty-printer renders it like this ("break-before-br" is false):

first line
second line
third line

The result is that a browser renders two linefeeds where just one should exist, causing ugly empty lines in the output. The problem gets worse if for some reason I use multiple passes of JTidy, adding more and more linefeeds.

How to fix: never ever add newlines after BR tags inside PRE sections.

Discussion

  • Alexander Kriegisch

    I just uploaded my humble try to fix the problem. Maybe it is a bit hacky and not the optimal solution, sorry this was my first look into your code and I have not been programming for a while. But at least locally it solves my problem and might be potentially beneficiary for other users, too.

     
  • Alexander Kriegisch

    Test case

     
  • Alexander Kriegisch

    The uploaded test case is part of a download from Galileo press (Galileo Openbook about iPhone development). It is freely available for download, so no worries there. I ran JTidy to clean up the HTML code and bumped into the problem with unwanted blank lines in the PRE sections. Just search the HTML file for

     and the corresponding sections in the original HTML and the result generated by JTidy-r938. It looks wrong without my patch and correct with my patch.

     

Log in to post a comment.

MongoDB Logo MongoDB