Better fix for 37059: initial space should be retained in selection-only case.

This commit is contained in:
akkana%netscape.com 2000-04-26 20:57:03 +00:00
Родитель edfaa7230c
Коммит 815d7692f5
4 изменённых файлов: 40 добавлений и 34 удалений

Просмотреть файл

@ -185,6 +185,7 @@ nsHTMLToTXTSinkStream::nsHTMLToTXTSinkStream()
mInWhitespace = PR_TRUE;
mPreFormatted = PR_FALSE;
mCacheLine = PR_FALSE;
mStartedOutput = PR_FALSE;
// initialize the tag stack to zero:
mTagStack = new nsHTMLTag[TagStackSize];
@ -243,13 +244,6 @@ nsHTMLToTXTSinkStream::Initialize(nsIOutputStream* aOutStream,
result = nsServiceManager::ReleaseService(kLWBrkCID, lf);
}
// If we're encoding only the selection, then we don't want to risk
// ignoring whitespace which might be significant:
// Unfortunately, this isn't the right solution because then we
// always get a space at the beginning of selection-only output!
// if (mFlags | nsIDocumentEncoder::OutputSelectionOnly)
// mInWhitespace = PR_FALSE;
return result;
}
@ -705,6 +699,8 @@ nsHTMLToTXTSinkStream::CloseContainer(const nsIParserNode& aNode)
// Fow now, I will only add a SPACE. Could be a TAB or something
// else but I'm not sure everything can handle the TAB so SPACE
// seems like a better solution.
// XXX This unfortunately means that every selection inside a
// XXX table cell ends up with an extraneous space after it.
if(!mInWhitespace) {
// Maybe add something else? Several spaces? A TAB? SPACE+TAB?
if(mCacheLine) {
@ -826,17 +822,24 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode)
// Otherwise, either we're collapsing to minimal text, or we're
// prettyprinting to mimic the html format, and in neither case
// does the formatting of the html source help us.
// One exception: at the very beginning of a selection,
// we want to preserve whitespace.
if (mFlags & nsIDocumentEncoder::OutputPreformatted ||
((mFlags & nsIDocumentEncoder::OutputFormatted)
&& (mTagStackIndex > 0)
&& (mTagStack[mTagStackIndex-1] == eHTMLTag_pre)) ||
(mPreFormatted && !mWrapColumn))
{
Write(text); // XXX: spacestuffing (maybe call AddToLine if mCacheLine==true)
} else if(!mInWhitespace) {
Write( NS_ConvertToString(" ") );
mInWhitespace = PR_TRUE;
}
{
Write(text); // XXX: spacestuffing (maybe call AddToLine if mCacheLine==true)
}
else if(!mInWhitespace ||
(!mStartedOutput
&& mFlags | nsIDocumentEncoder::OutputSelectionOnly))
{
mInWhitespace = PR_FALSE;
Write( NS_ConvertToString(" ") );
mInWhitespace = PR_TRUE;
}
}
else if (type == eHTMLTag_newline)
{
@ -945,6 +948,9 @@ nsHTMLToTXTSinkStream::FlushLine()
*/
void nsHTMLToTXTSinkStream::WriteSimple(nsString& aString)
{
if (aString.Length() > 0)
mStartedOutput = PR_TRUE;
// First, replace all nbsp characters with spaces,
// which the unicode encoder won't do for us.
static PRUnichar nbsp = 160;
@ -1167,10 +1173,6 @@ nsHTMLToTXTSinkStream::WriteQuotesAndIndent()
}
#ifdef DEBUG_akkana_not
#define DEBUG_wrapping 1
#endif
//
// Write a string, wrapping appropriately to mWrapColumn.
// This routine also handles indentation and mail-quoting,

Просмотреть файл

@ -179,6 +179,7 @@ protected:
PRBool mInWhitespace;
PRBool mPreFormatted;
PRBool mCacheLine; // If the line should be cached before output. This makes it possible to do smarter wrapping.
PRBool mStartedOutput; // we've produced at least a character
nsString mURL;

Просмотреть файл

@ -185,6 +185,7 @@ nsHTMLToTXTSinkStream::nsHTMLToTXTSinkStream()
mInWhitespace = PR_TRUE;
mPreFormatted = PR_FALSE;
mCacheLine = PR_FALSE;
mStartedOutput = PR_FALSE;
// initialize the tag stack to zero:
mTagStack = new nsHTMLTag[TagStackSize];
@ -243,13 +244,6 @@ nsHTMLToTXTSinkStream::Initialize(nsIOutputStream* aOutStream,
result = nsServiceManager::ReleaseService(kLWBrkCID, lf);
}
// If we're encoding only the selection, then we don't want to risk
// ignoring whitespace which might be significant:
// Unfortunately, this isn't the right solution because then we
// always get a space at the beginning of selection-only output!
// if (mFlags | nsIDocumentEncoder::OutputSelectionOnly)
// mInWhitespace = PR_FALSE;
return result;
}
@ -705,6 +699,8 @@ nsHTMLToTXTSinkStream::CloseContainer(const nsIParserNode& aNode)
// Fow now, I will only add a SPACE. Could be a TAB or something
// else but I'm not sure everything can handle the TAB so SPACE
// seems like a better solution.
// XXX This unfortunately means that every selection inside a
// XXX table cell ends up with an extraneous space after it.
if(!mInWhitespace) {
// Maybe add something else? Several spaces? A TAB? SPACE+TAB?
if(mCacheLine) {
@ -826,17 +822,24 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode)
// Otherwise, either we're collapsing to minimal text, or we're
// prettyprinting to mimic the html format, and in neither case
// does the formatting of the html source help us.
// One exception: at the very beginning of a selection,
// we want to preserve whitespace.
if (mFlags & nsIDocumentEncoder::OutputPreformatted ||
((mFlags & nsIDocumentEncoder::OutputFormatted)
&& (mTagStackIndex > 0)
&& (mTagStack[mTagStackIndex-1] == eHTMLTag_pre)) ||
(mPreFormatted && !mWrapColumn))
{
Write(text); // XXX: spacestuffing (maybe call AddToLine if mCacheLine==true)
} else if(!mInWhitespace) {
Write( NS_ConvertToString(" ") );
mInWhitespace = PR_TRUE;
}
{
Write(text); // XXX: spacestuffing (maybe call AddToLine if mCacheLine==true)
}
else if(!mInWhitespace ||
(!mStartedOutput
&& mFlags | nsIDocumentEncoder::OutputSelectionOnly))
{
mInWhitespace = PR_FALSE;
Write( NS_ConvertToString(" ") );
mInWhitespace = PR_TRUE;
}
}
else if (type == eHTMLTag_newline)
{
@ -945,6 +948,9 @@ nsHTMLToTXTSinkStream::FlushLine()
*/
void nsHTMLToTXTSinkStream::WriteSimple(nsString& aString)
{
if (aString.Length() > 0)
mStartedOutput = PR_TRUE;
// First, replace all nbsp characters with spaces,
// which the unicode encoder won't do for us.
static PRUnichar nbsp = 160;
@ -1167,10 +1173,6 @@ nsHTMLToTXTSinkStream::WriteQuotesAndIndent()
}
#ifdef DEBUG_akkana_not
#define DEBUG_wrapping 1
#endif
//
// Write a string, wrapping appropriately to mWrapColumn.
// This routine also handles indentation and mail-quoting,

Просмотреть файл

@ -179,6 +179,7 @@ protected:
PRBool mInWhitespace;
PRBool mPreFormatted;
PRBool mCacheLine; // If the line should be cached before output. This makes it possible to do smarter wrapping.
PRBool mStartedOutput; // we've produced at least a character
nsString mURL;