Fix the HTML serializer to not do fancy linebreaking when "raw" output is

requested.  Use this in innerHTML.  Bug 89780, r+sr=peterv
This commit is contained in:
bzbarsky%mit.edu 2005-02-07 17:24:05 +00:00
parent fa292fa28a
commit e1a5653cce
3 changed files with 22 additions and 8 deletions

View File

@ -117,23 +117,34 @@ public:
// (Probably not well tested for HTML output.)
OutputFormatted = 2,
// OutputRaw is used by copying text from widgets
// Don't do prettyprinting of HTML. Don't do any wrapping that's not in
// the existing HTML source. This option overrides OutputFormatted if both
// are set. Note that this option does not affect entity conversion.
OutputRaw = 4,
// No html head tags
OutputBodyOnly = 8,
// Wrap even if we're not doing formatted output (e.g. for text fields)
// XXXbz this doesn't seem to be used by all serializers... document? How
// does this interact with
// OutputFormatted/OutputRaw/OutputWrap/OutputFormatFlowed?
OutputPreformatted = 16,
// Output as though the content is preformatted
// (e.g. maybe it's wrapped in a MOZ_PRE or MOZ_PRE_WRAP style tag)
// XXXbz this doesn't seem to be used by all serializers... document? How
// does this interact with
// OutputFormatted/OutputRaw/OutputPreformatted/OutputFormatFlowed?
OutputWrap = 32,
// Output for format flowed (RFC 2646). This is used when converting
// to text for mail sending. This differs just slightly
// but in an important way from normal formatted, and that is that
// lines are space stuffed. This can't (correctly) be done later.
// XXXbz this doesn't seem to be used by all serializers... document? How
// does this interact with
// OutputFormatted/OutputRaw/OutputPreformatted/OutputWrap?
OutputFormatFlowed = 64,
// Convert links, image src, and script src to absolute URLs when possible

View File

@ -189,6 +189,12 @@ nsHTMLContentSerializer::AppendText(nsIDOMText* aText,
if (mPreLevel > 0) {
AppendToStringConvertLF(data, aStr);
}
else if (mFlags & nsIDocumentEncoder::OutputRaw) {
PRInt32 lastNewlineOffset = data.RFindChar('\n');
AppendToString(data, aStr);
if (lastNewlineOffset != kNotFound)
mColPos = data.Length() - lastNewlineOffset;
}
else if (!mDoFormat) {
PRInt32 lastNewlineOffset = kNotFound;
PRBool hasLongLines = HasLongLines(data, lastNewlineOffset);
@ -202,12 +208,6 @@ nsHTMLContentSerializer::AppendText(nsIDOMText* aText,
AppendToStringConvertLF(data, aStr);
}
}
else if (mFlags & nsIDocumentEncoder::OutputRaw) {
PRInt32 lastNewlineOffset = data.RFindChar('\n');
AppendToString(data, aStr);
if (lastNewlineOffset != kNotFound)
mColPos = data.Length() - lastNewlineOffset;
}
else {
AppendToStringWrapped(data, aStr, PR_FALSE);
}

View File

@ -888,7 +888,10 @@ nsGenericHTMLElement::GetInnerHTML(nsAString& aInnerHTML)
docEncoder->Init(doc, NS_LITERAL_STRING("text/html"),
nsIDocumentEncoder::OutputEncodeBasicEntities |
nsIDocumentEncoder::OutputLFLineBreak);
// Output DOM-standard newlines
nsIDocumentEncoder::OutputLFLineBreak |
// Don't do linebreaking that's not present in the source
nsIDocumentEncoder::OutputRaw);
nsCOMPtr<nsIDOMRange> range(new nsRange);
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);