36809: fix plaintext output of img tags. r=BenB

This commit is contained in:
akkana%netscape.com 2000-09-01 23:36:18 +00:00
Родитель a4e68e2cb1
Коммит 85292633f8
2 изменённых файлов: 74 добавлений и 76 удалений

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

@ -723,43 +723,6 @@ nsHTMLToTXTSinkStream::OpenContainer(const nsIParserNode& aNode)
mIndent += gTabSize; // Check for some maximum value?
}
else if (type == eHTMLTag_img)
{
/* Output (in decreasing order of preference)
alt, title or src (URI) attribute */
// See <http://www.w3.org/TR/REC-html40/struct/objects.html#edef-IMG>
nsAutoString desc, temp;
if (NS_SUCCEEDED(GetValueOfAttribute(aNode, "alt", desc)))
{
if (!desc.IsEmpty())
{
temp.AppendWithConversion(" ["); // Should we output chars at all here?
desc.StripChars("\"");
temp += desc;
temp.AppendWithConversion(" ]");
}
// If the alt attribute has an empty value (|alt=""|), output nothing
}
else if (NS_SUCCEEDED(GetValueOfAttribute(aNode, "title", desc))
&& !desc.IsEmpty())
{
temp.AppendWithConversion(" [");
desc.StripChars("\"");
temp += desc;
temp.AppendWithConversion("] ");
}
else if (NS_SUCCEEDED(GetValueOfAttribute(aNode, "src", desc))
&& !desc.IsEmpty())
{
temp.AppendWithConversion(" <");
desc.StripChars("\"");
temp += desc;
temp.AppendWithConversion("> ");
}
if (!temp.IsEmpty())
Write(temp);
}
else if (type == eHTMLTag_a && !IsConverted(aNode))
{
nsAutoString url;
@ -1025,6 +988,42 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode)
EnsureVerticalSpace(0);
}
else if (type == eHTMLTag_img)
{
/* Output (in decreasing order of preference)
alt, title or src (URI) attribute */
// See <http://www.w3.org/TR/REC-html40/struct/objects.html#edef-IMG>
nsAutoString desc, temp;
if (NS_SUCCEEDED(GetValueOfAttribute(aNode, "alt", desc)))
{
if (!desc.IsEmpty())
{
temp.AppendWithConversion(" ["); // Should we output chars at all here?
desc.StripChars("\"");
temp += desc;
temp.AppendWithConversion("]");
}
// If the alt attribute has an empty value (|alt=""|), output nothing
}
else if (NS_SUCCEEDED(GetValueOfAttribute(aNode, "title", desc))
&& !desc.IsEmpty())
{
temp.AppendWithConversion(" [");
desc.StripChars("\"");
temp += desc;
temp.AppendWithConversion("] ");
}
else if (NS_SUCCEEDED(GetValueOfAttribute(aNode, "src", desc))
&& !desc.IsEmpty())
{
temp.AppendWithConversion(" <");
desc.StripChars("\"");
temp += desc;
temp.AppendWithConversion("> ");
}
if (!temp.IsEmpty())
Write(temp);
}
return NS_OK;
}

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

@ -723,43 +723,6 @@ nsHTMLToTXTSinkStream::OpenContainer(const nsIParserNode& aNode)
mIndent += gTabSize; // Check for some maximum value?
}
else if (type == eHTMLTag_img)
{
/* Output (in decreasing order of preference)
alt, title or src (URI) attribute */
// See <http://www.w3.org/TR/REC-html40/struct/objects.html#edef-IMG>
nsAutoString desc, temp;
if (NS_SUCCEEDED(GetValueOfAttribute(aNode, "alt", desc)))
{
if (!desc.IsEmpty())
{
temp.AppendWithConversion(" ["); // Should we output chars at all here?
desc.StripChars("\"");
temp += desc;
temp.AppendWithConversion(" ]");
}
// If the alt attribute has an empty value (|alt=""|), output nothing
}
else if (NS_SUCCEEDED(GetValueOfAttribute(aNode, "title", desc))
&& !desc.IsEmpty())
{
temp.AppendWithConversion(" [");
desc.StripChars("\"");
temp += desc;
temp.AppendWithConversion("] ");
}
else if (NS_SUCCEEDED(GetValueOfAttribute(aNode, "src", desc))
&& !desc.IsEmpty())
{
temp.AppendWithConversion(" <");
desc.StripChars("\"");
temp += desc;
temp.AppendWithConversion("> ");
}
if (!temp.IsEmpty())
Write(temp);
}
else if (type == eHTMLTag_a && !IsConverted(aNode))
{
nsAutoString url;
@ -1025,6 +988,42 @@ nsHTMLToTXTSinkStream::AddLeaf(const nsIParserNode& aNode)
EnsureVerticalSpace(0);
}
else if (type == eHTMLTag_img)
{
/* Output (in decreasing order of preference)
alt, title or src (URI) attribute */
// See <http://www.w3.org/TR/REC-html40/struct/objects.html#edef-IMG>
nsAutoString desc, temp;
if (NS_SUCCEEDED(GetValueOfAttribute(aNode, "alt", desc)))
{
if (!desc.IsEmpty())
{
temp.AppendWithConversion(" ["); // Should we output chars at all here?
desc.StripChars("\"");
temp += desc;
temp.AppendWithConversion("]");
}
// If the alt attribute has an empty value (|alt=""|), output nothing
}
else if (NS_SUCCEEDED(GetValueOfAttribute(aNode, "title", desc))
&& !desc.IsEmpty())
{
temp.AppendWithConversion(" [");
desc.StripChars("\"");
temp += desc;
temp.AppendWithConversion("] ");
}
else if (NS_SUCCEEDED(GetValueOfAttribute(aNode, "src", desc))
&& !desc.IsEmpty())
{
temp.AppendWithConversion(" <");
desc.StripChars("\"");
temp += desc;
temp.AppendWithConversion("> ");
}
if (!temp.IsEmpty())
Write(temp);
}
return NS_OK;
}