Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Blank lines discarded #20

Closed
GoogleCodeExporter opened this issue Apr 22, 2015 · 7 comments
Closed

Blank lines discarded #20

GoogleCodeExporter opened this issue Apr 22, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. <pre class="prettyprint">&lt;html&gt;
2.
3. &lt;head&gt;

(Please include HTML, not just your source code)


What is the expected output?  What do you see instead?
EXPECTED
<html>

<head>

GETTING
<html>
<head>

What version are you using?  On what browser?
Version: 22 May 20077
Browser: IE 6.0

Please provide any additional information below.
I fixed the code by adding &nbsp; in front of <br>.
This code is in prettyPrintOne().
   html = html
         .replace(/(\r\n?|\n| ) /g, '$1nbsp;')
         .replace(/\r\n?|\n/g, '&nbsp;<br>');

Original issue reported on code.google.com by tbuch...@gmail.com on 26 Sep 2007 at 3:38

@GoogleCodeExporter
Copy link
Author

I can't repeat the error on either Firefox 2 or IE 6.

I added the following to the unittest and it passes for me.
Am I misunderstanding the bug?

$ svn diff tests/prettify_test.html
Index: tests/prettify_test.html
===================================================================
--- tests/prettify_test.html    (revision 34)
+++ tests/prettify_test.html    (working copy)
@@ -458,7 +458,12 @@
 <p>And another one inside the end tag</p<!-- GOTCHA!! -->>
 </pre>

+<h1>Bug 20 - missing blank lines</h1>
+<pre class="prettyprint" id="issue20"
+><html>

+<head></pre>
+
 </body>

 <script type="text/javascript">
@@ -1051,7 +1056,11 @@
       '`COM<!-- There\'s an `END<acronym title="tag soup">`COMHTML`END' +
            '</acronym>`COM comment in my comment -->`END`PLN<br>' +
       '`END`PUN<`END`TAGp`END`PUN>`END`PLNAnd another one inside the end
tag`END' +
-      '`PUN</`END`TAGp`END`PUN>`END')
+      '`PUN</`END`TAGp`END`PUN>`END'),
+  issue20: (
+      '`PUN<`END`TAGhtml`END`PUN>`END`PLN<br>' +
+      '<br>' +
+      '`END`PUN<`END`TAGhead`END`PUN>`END')
 };

Original comment by mikesamuel@gmail.com on 23 Oct 2007 at 1:39

@GoogleCodeExporter
Copy link
Author

I do not know why you cannot reproduce it. I KNOW that every blank line was 
being 
ignored/removed when Prettify ran. Note that there is nothing on the lines, not 
even 
a <br>.

My editing platform is Windows XP, using Visual Studio 2003. So, line breaks 
are a 
CR LF pair (\r\n). And I was using the 22 May 2007 version of Prettify.

Original comment by tbuch...@gmail.com on 24 Oct 2007 at 1:57

@GoogleCodeExporter
Copy link
Author

After some testing, I confirm that IE browsers collapse multiple adjacent <br>s 
(e.g.
<br><br><br>) into 1 line break. 

prettify.js (revision 39) passes the "Bug 20" test in prettify_test.html on IE6,
simply because all <br>s have been replaced with 
document.createTextNode('\r\n').
This problem will still show up in IE7. I attach a test file to further 
illustrate
this issue.

A possible workaround is to add ' ' in front of every <br>. This workaround 
also
seems to work along with other browsers (tested on FF3, Opera9.5, Safari3.1.2). 

Here's a patch of the workaround:

--- prettify.js (revision 39)
+++ prettify.js (working copy)
@@ -1158,6 +1158,11 @@
                     document.createTextNode('\r\n'), lineBreak);
               }
             }
+            // IE collapses multiple adjacient <br>s into 1 line break.
+            // Prefix every <br> with ' ' can prevent such IE's behavior.
+            if (!isIE6) {
+              cs.innerHTML = cs.innerHTML.replace(/(<br[^>]*>)/ig, ' $1');
+            }
           }
         }
       }

Original comment by teohuiming on 7 Jul 2008 at 3:20

Attachments:

@GoogleCodeExporter
Copy link
Author

Would you please accept this patch? With IE8, this issue is still there. And 
for 
languages support multiple lines string (Ruby, Python, Perl...), this issue 
will 
break the code.

Original comment by bbr...@gmail.com on 8 Mar 2009 at 4:33

@GoogleCodeExporter
Copy link
Author

Original comment by mikesamuel@gmail.com on 14 May 2009 at 6:00

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

@r69

Original comment by mikesamuel@gmail.com on 14 May 2009 at 6:15

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Has this fix been put into production yet? I'm still seeing problem with IE8, 
for 
example, the following displays fine in Firefox 3, but all of the indentation 
whitespace is collapsed in IE8:

http://code.google.com/p/gaevfs/source/browse/trunk/src/com/newatlanta/commons/v
fs/pr
ovider/gae/GaeVfsServlet.java

I got here by following links from this issue:

http://code.google.com/p/support/issues/detail?id=1947

Original comment by vbonfa...@gmail.com on 24 Jun 2009 at 11:36

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants