mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-04 04:58:00 +00:00
Fix formatted plaintext output -- it wasn't following prettyprint or wrap length
This commit is contained in:
parent
89545a8ee9
commit
5c1253edca
@ -456,7 +456,8 @@ nsTextEncoder::EncodeToString(nsString& aOutputString)
|
||||
{
|
||||
nsIHTMLContentSink* sink = nsnull;
|
||||
|
||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString, mPrettyPrint);
|
||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString,
|
||||
mWrapColumn, mPrettyPrint);
|
||||
|
||||
if (sink && NS_SUCCEEDED(rv))
|
||||
{
|
||||
|
@ -152,6 +152,7 @@ nsTextEditor::nsTextEditor()
|
||||
// NS_INIT_REFCNT();
|
||||
mRules = nsnull;
|
||||
mMaxTextLength = -1;
|
||||
mWrapColumn = 72;
|
||||
}
|
||||
|
||||
nsTextEditor::~nsTextEditor()
|
||||
@ -1566,7 +1567,8 @@ NS_IMETHODIMP nsTextEditor::OutputTextToString(nsString& aOutputString, PRBool a
|
||||
wc = 0;
|
||||
else
|
||||
wc = (PRUint32)mWrapColumn;
|
||||
(void)encoder->SetWrapColumn(wc);
|
||||
if (mWrapColumn > 0)
|
||||
(void)encoder->SetWrapColumn(wc);
|
||||
}
|
||||
|
||||
rv = encoder->EncodeToString(aOutputString);
|
||||
|
@ -224,8 +224,7 @@ nsHTMLToTXTSinkStream::nsHTMLToTXTSinkStream(nsIOutputStream* aStream,
|
||||
mStream = aStream;
|
||||
mString = aString;
|
||||
mPrettyPrint = PR_FALSE;
|
||||
mPreformatted = PR_FALSE;
|
||||
mWrapColumn = 72; // XXX magic number, obviously needs to be settable
|
||||
mWrapColumn = 72; // XXX magic number, we expect someone to reset this
|
||||
|
||||
// initialize the tag stack to zero:
|
||||
mTagStack = new nsHTMLTag[TagStackSize];
|
||||
@ -677,7 +676,6 @@ nsHTMLToTXTSinkStream::OpenContainer(const nsIParserNode& aNode)
|
||||
mIndent += gTabSize;
|
||||
else if (type == eHTMLTag_pre)
|
||||
{
|
||||
mPreformatted = PR_TRUE;
|
||||
nsString temp(NS_LINEBREAK);
|
||||
Write(temp);
|
||||
mColPos = 0;
|
||||
@ -733,9 +731,6 @@ nsHTMLToTXTSinkStream::CloseContainer(const nsIParserNode& aNode)
|
||||
if (mTagStackIndex > 0)
|
||||
--mTagStackIndex;
|
||||
|
||||
if (type == eHTMLTag_pre)
|
||||
mPreformatted = PR_FALSE;
|
||||
|
||||
else if (type == eHTMLTag_ol)
|
||||
--mOLStackIndex;
|
||||
|
||||
@ -819,20 +814,22 @@ 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.
|
||||
else if (mPrettyPrint && mPreformatted && type == eHTMLTag_whitespace)
|
||||
else if (mPrettyPrint
|
||||
&& (mTagStackIndex > 0)
|
||||
&& (mTagStack[mTagStackIndex-1] == eHTMLTag_pre))
|
||||
{
|
||||
if (mPrettyPrint)
|
||||
if (type == eHTMLTag_whitespace)
|
||||
{
|
||||
text = aNode.GetText();
|
||||
Write(text);
|
||||
mColPos += text.Length();
|
||||
}
|
||||
}
|
||||
else if (mPrettyPrint && mPreformatted && type == eHTMLTag_newline)
|
||||
{
|
||||
nsString temp(NS_LINEBREAK);
|
||||
Write(temp);
|
||||
mColPos = 0;
|
||||
else if (type == eHTMLTag_newline)
|
||||
{
|
||||
nsString temp(NS_LINEBREAK);
|
||||
Write(temp);
|
||||
mColPos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -130,7 +130,6 @@ protected:
|
||||
PRInt32 mIndent;
|
||||
PRInt32 mColPos;
|
||||
PRBool mDoOutput;
|
||||
PRBool mPreformatted;
|
||||
PRBool mPrettyPrint;
|
||||
PRUint32 mWrapColumn;
|
||||
|
||||
|
@ -456,7 +456,8 @@ nsTextEncoder::EncodeToString(nsString& aOutputString)
|
||||
{
|
||||
nsIHTMLContentSink* sink = nsnull;
|
||||
|
||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString, mPrettyPrint);
|
||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString,
|
||||
mWrapColumn, mPrettyPrint);
|
||||
|
||||
if (sink && NS_SUCCEEDED(rv))
|
||||
{
|
||||
|
@ -224,8 +224,7 @@ nsHTMLToTXTSinkStream::nsHTMLToTXTSinkStream(nsIOutputStream* aStream,
|
||||
mStream = aStream;
|
||||
mString = aString;
|
||||
mPrettyPrint = PR_FALSE;
|
||||
mPreformatted = PR_FALSE;
|
||||
mWrapColumn = 72; // XXX magic number, obviously needs to be settable
|
||||
mWrapColumn = 72; // XXX magic number, we expect someone to reset this
|
||||
|
||||
// initialize the tag stack to zero:
|
||||
mTagStack = new nsHTMLTag[TagStackSize];
|
||||
@ -677,7 +676,6 @@ nsHTMLToTXTSinkStream::OpenContainer(const nsIParserNode& aNode)
|
||||
mIndent += gTabSize;
|
||||
else if (type == eHTMLTag_pre)
|
||||
{
|
||||
mPreformatted = PR_TRUE;
|
||||
nsString temp(NS_LINEBREAK);
|
||||
Write(temp);
|
||||
mColPos = 0;
|
||||
@ -733,9 +731,6 @@ nsHTMLToTXTSinkStream::CloseContainer(const nsIParserNode& aNode)
|
||||
if (mTagStackIndex > 0)
|
||||
--mTagStackIndex;
|
||||
|
||||
if (type == eHTMLTag_pre)
|
||||
mPreformatted = PR_FALSE;
|
||||
|
||||
else if (type == eHTMLTag_ol)
|
||||
--mOLStackIndex;
|
||||
|
||||
@ -819,20 +814,22 @@ 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.
|
||||
else if (mPrettyPrint && mPreformatted && type == eHTMLTag_whitespace)
|
||||
else if (mPrettyPrint
|
||||
&& (mTagStackIndex > 0)
|
||||
&& (mTagStack[mTagStackIndex-1] == eHTMLTag_pre))
|
||||
{
|
||||
if (mPrettyPrint)
|
||||
if (type == eHTMLTag_whitespace)
|
||||
{
|
||||
text = aNode.GetText();
|
||||
Write(text);
|
||||
mColPos += text.Length();
|
||||
}
|
||||
}
|
||||
else if (mPrettyPrint && mPreformatted && type == eHTMLTag_newline)
|
||||
{
|
||||
nsString temp(NS_LINEBREAK);
|
||||
Write(temp);
|
||||
mColPos = 0;
|
||||
else if (type == eHTMLTag_newline)
|
||||
{
|
||||
nsString temp(NS_LINEBREAK);
|
||||
Write(temp);
|
||||
mColPos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -130,7 +130,6 @@ protected:
|
||||
PRInt32 mIndent;
|
||||
PRInt32 mColPos;
|
||||
PRBool mDoOutput;
|
||||
PRBool mPreformatted;
|
||||
PRBool mPrettyPrint;
|
||||
PRUint32 mWrapColumn;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user