bug 144998: Empty lines under quotes are doubled. Patch by Shotaro Kamio <skamio@netscape.net>, Koike Kazuhiko <kazhik@mozilla.gr.jp>, Wolfgang Rosenauer <mozilla@rfosenauer.org>, and me. r=akkana sr=jst a=shaver

git-svn-id: svn://10.0.0.236/trunk@173967 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mrbkap%gmail.com
2005-06-01 19:31:47 +00:00
parent 8acfafe4ea
commit b3293f50e6
4 changed files with 101 additions and 24 deletions

View File

@@ -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 <blockquote type=cite> 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<totLen) {
if(mAtFirstColumn) {
OutputQuotesAndIndent();
}
PRBool outputQuotes = mAtFirstColumn;
PRBool atFirstColumn = mAtFirstColumn;
PRBool outputLineBreak = PR_FALSE;
// Find one of '\n' or '\r' using iterators since nsAString
// doesn't have the old FindCharInSet function.
@@ -1696,20 +1712,19 @@ nsPlainTextSerializer::Write(const nsAString& aString)
mInWhitespace = PR_FALSE;
}
}
Output(stringpart);
mCurrentLine.Assign(stringpart);
mEmptyLines=-1;
mAtFirstColumn = mAtFirstColumn && (totLen-bol)==0;
atFirstColumn = mAtFirstColumn && (totLen-bol)==0;
bol = totLen;
}
else {
// There is a newline
nsAutoString stringpart(Substring(aString, bol, newline-bol));
mInWhitespace = PR_TRUE;
Output(stringpart);
// and write the newline
Output(mLineBreak);
mCurrentLine.Assign(stringpart);
outputLineBreak = PR_TRUE;
mEmptyLines=0;
mAtFirstColumn = PR_TRUE;
atFirstColumn = PR_TRUE;
bol = newline+1;
if('\r' == *iter && bol < totLen && '\n' == *++iter) {
// There was a CRLF in the input. This used to be illegal and
@@ -1718,8 +1733,22 @@ nsPlainTextSerializer::Write(const nsAString& aString)
bol++;
}
}
if(outputQuotes) {
// Note: this call messes with mAtFirstColumn
OutputQuotesAndIndent();
}
Output(mCurrentLine);
if (outputLineBreak) {
Output(mLineBreak);
}
mAtFirstColumn = atFirstColumn;
}
// Reset mCurrentLine.
mCurrentLine.Truncate();
#ifdef DEBUG_wrapping
printf("No wrapping: newline is %d, totLen is %d\n",
newline, totLen);

View File

@@ -193,6 +193,11 @@ protected:
PRPackedBool mStructs; // Output structs (pref)
// If we've just written out a cite blockquote, we need to remember it
// so we don't duplicate spaces before a <pre wrap> (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.

View File

@@ -70,5 +70,31 @@ The observed of all observers, quite, quite down!
<p>
Now we're outside all blockquotes.
</p>
<p>
Now let's test some more complicated quotes:<br>
</p>
On 02/22/2003 06:29 AM, Koike Kazuhiko wrote:
<br><blockquote type=cite>abc
<br></blockquote>def
<br>
<br>
On 02/23/2003 06:49 AM, Blake Kaplan wrote:
<br><blockquote type=cite>On 02/22/2003 06:29 AM, Koike Kazuhiko wrote:
<br><blockquote type=cite>abc
<br></blockquote>def
<br></blockquote>ghi
<br><br>
The alternate method of quoting:<br><br>
<pre wrap>On 02/22/2003 06:29 AM, Koike Kazuhiko wrote:
</pre><blockquote type=cite><pre wrap>abc
</pre></blockquote><pre wrap><!---->def
</pre></body>
</body>
</html>

View File

@@ -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