From b3293f50e6ced997dfe95fa6c00d2ee4cab0c063 Mon Sep 17 00:00:00 2001 From: "mrbkap%gmail.com" Date: Wed, 1 Jun 2005 19:31:47 +0000 Subject: [PATCH] bug 144998: Empty lines under quotes are doubled. Patch by Shotaro Kamio , Koike Kazuhiko , Wolfgang Rosenauer , and me. r=akkana sr=jst a=shaver git-svn-id: svn://10.0.0.236/trunk@173967 18797224-902f-48f8-a5cc-f745e15eee43 --- .../base/src/nsPlainTextSerializer.cpp | 75 +++++++++++++------ .../content/base/src/nsPlainTextSerializer.h | 5 ++ .../htmlparser/tests/outsinks/mailquote.html | 26 +++++++ .../htmlparser/tests/outsinks/mailquote.out | 19 ++++- 4 files changed, 101 insertions(+), 24 deletions(-) diff --git a/mozilla/content/base/src/nsPlainTextSerializer.cpp b/mozilla/content/base/src/nsPlainTextSerializer.cpp index 67fff037e99..c9bb9186f1f 100644 --- a/mozilla/content/base/src/nsPlainTextSerializer.cpp +++ b/mozilla/content/base/src/nsPlainTextSerializer.cpp @@ -104,6 +104,7 @@ nsPlainTextSerializer::nsPlainTextSerializer() mHeaderStrategy = 1 /*indent increasingly*/; // ditto mQuotesPreformatted = PR_FALSE; // ditto mDontWrapAnyQuotes = PR_FALSE; // ditto + mHasWrittenCiteBlockquote = PR_FALSE; mSpanLevel = 0; for (PRInt32 i = 0; i <= 6; i++) { mHeaderCounter[i] = 0; @@ -634,7 +635,17 @@ nsPlainTextSerializer::DoOpenContainer(const nsIParserNode* aNode, PRInt32 aTag) return NS_OK; } - if (mLineBreakDue) + PRBool isInCiteBlockquote = PR_FALSE; + + // XXX special-case
so that we don't add additional + // newlines before the text. + if (aTag == eHTMLTag_blockquote) { + nsAutoString value; + nsresult rv = GetAttributeValue(aNode, nsHTMLAtoms::type, value); + isInCiteBlockquote = NS_SUCCEEDED(rv) && value.EqualsIgnoreCase("cite"); + } + + if (mLineBreakDue && !isInCiteBlockquote) EnsureVerticalSpace(mFloatingLines); // Check if this tag's content that should not be output @@ -709,8 +720,17 @@ nsPlainTextSerializer::DoOpenContainer(const nsIParserNode* aNode, PRInt32 aTag) return NS_OK; } - if (type == eHTMLTag_p || type == eHTMLTag_pre) { - EnsureVerticalSpace(1); // Should this be 0 in unformatted case? + if (type == eHTMLTag_p) + EnsureVerticalSpace(1); + else if (type == eHTMLTag_pre) { + if (GetLastBool(mIsInCiteBlockquote)) + EnsureVerticalSpace(0); + else if (mHasWrittenCiteBlockquote) { + EnsureVerticalSpace(0); + mHasWrittenCiteBlockquote = PR_FALSE; + } + else + EnsureVerticalSpace(1); } else if (type == eHTMLTag_tr) { PushBool(mHasWrittenCellsForRow, PR_FALSE); @@ -801,19 +821,14 @@ nsPlainTextSerializer::DoOpenContainer(const nsIParserNode* aNode, PRInt32 aTag) ++mSpanLevel; } else if (type == eHTMLTag_blockquote) { - EnsureVerticalSpace(1); - - nsAutoString value; - nsresult rv = GetAttributeValue(aNode, nsHTMLAtoms::type, value); - - PRBool isInCiteBlockquote = - NS_SUCCEEDED(rv) && value.LowerCaseEqualsLiteral("cite"); // Push PushBool(mIsInCiteBlockquote, isInCiteBlockquote); if (isInCiteBlockquote) { + EnsureVerticalSpace(0); mCiteQuoteLevel++; } else { + EnsureVerticalSpace(1); mIndent += kTabSize; // Check for some maximum value? } } @@ -964,7 +979,7 @@ nsPlainTextSerializer::DoCloseContainer(PRInt32 aTag) mLineBreakDue = PR_TRUE; } else if (type == eHTMLTag_pre) { - mFloatingLines = 1; + mFloatingLines = GetLastBool(mIsInCiteBlockquote) ? 0 : 1; mLineBreakDue = PR_TRUE; } else if (type == eHTMLTag_ul) { @@ -1008,12 +1023,13 @@ nsPlainTextSerializer::DoCloseContainer(PRInt32 aTag) if (isInCiteBlockquote) { mCiteQuoteLevel--; + mFloatingLines = 0; + mHasWrittenCiteBlockquote = PR_TRUE; } else { mIndent -= kTabSize; + mFloatingLines = 1; } - - mFloatingLines = 1; mLineBreakDue = PR_TRUE; } else if (IsBlockLevel(aTag) @@ -1658,13 +1674,13 @@ nsPlainTextSerializer::Write(const nsAString& aString) if (!mCurrentLine.IsEmpty()) { FlushLine(); } - + // Put the mail quote "> " chars in, if appropriate. // Have to put it in before every line. while(bol (which mail uses to quote + // old messages). + PRPackedBool mHasWrittenCiteBlockquote; + PRInt32 mIndent; // mInIndentString keeps a header that has to be written in the indent. // That could be, for instance, the bullet in a bulleted list. diff --git a/mozilla/parser/htmlparser/tests/outsinks/mailquote.html b/mozilla/parser/htmlparser/tests/outsinks/mailquote.html index a39cdf2b51f..f8fdb73ac94 100644 --- a/mozilla/parser/htmlparser/tests/outsinks/mailquote.html +++ b/mozilla/parser/htmlparser/tests/outsinks/mailquote.html @@ -70,5 +70,31 @@ The observed of all observers, quite, quite down!

Now we're outside all blockquotes. +

+ +

+Now let's test some more complicated quotes:
+

+ +On 02/22/2003 06:29 AM, Koike Kazuhiko wrote: +
abc +
def +
+
+ +On 02/23/2003 06:49 AM, Blake Kaplan wrote: +
On 02/22/2003 06:29 AM, Koike Kazuhiko wrote: +
abc +
def +
ghi +

+ +The alternate method of quoting:

+ +
On 02/22/2003 06:29 AM, Koike Kazuhiko wrote:
+
abc
+
def
+
+
diff --git a/mozilla/parser/htmlparser/tests/outsinks/mailquote.out b/mozilla/parser/htmlparser/tests/outsinks/mailquote.out index 7336ee8e083..e58bcebff2b 100644 --- a/mozilla/parser/htmlparser/tests/outsinks/mailquote.out +++ b/mozilla/parser/htmlparser/tests/outsinks/mailquote.out @@ -15,9 +15,26 @@ quotations get wrapped: > >> /(The next line does not end with a *br* tag.)./ >> Oh, what a rogue and peasant slave am I. -> > /(Neither does the next line:)/ > The observed of all observers, quite, quite down! Now we're outside all blockquotes. +Now let's test some more complicated quotes: + +On 02/22/2003 06:29 AM, Koike Kazuhiko wrote: +> abc +def + +On 02/23/2003 06:49 AM, Blake Kaplan wrote: +> On 02/22/2003 06:29 AM, Koike Kazuhiko wrote: +>> abc +> def +ghi + +The alternate method of quoting: + +On 02/22/2003 06:29 AM, Koike Kazuhiko wrote: +> abc +def +