Bug 595280: AddonRepository should convert HTML to plain text. r=Unfocused, a=blocking-betaN

This commit is contained in:
Dave Townsend 2010-09-13 10:35:37 -07:00
parent 758c4c015b
commit 65115f2377
8 changed files with 53 additions and 20 deletions

View File

@ -91,15 +91,20 @@ const PROP_MULTI = ["developers", "screenshots"]
const STRING_KEY_MAP = {
name: "name",
version: "version",
summary: "description",
description: "fullDescription",
developer_comments: "developerComments",
eula: "eula",
icon: "iconURL",
homepage: "homepageURL",
support: "supportURL"
};
// A map between XML keys to AddonSearchResult keys for string values
// that require parsing from HTML
const HTML_KEY_MAP = {
summary: "description",
description: "fullDescription",
developer_comments: "developerComments",
eula: "eula"
};
// A map between XML keys to AddonSearchResult keys for integer values
// that require no extra parsing from XML
const INTEGER_KEY_MAP = {
@ -109,6 +114,23 @@ const INTEGER_KEY_MAP = {
};
function convertHTMLToPlainText(html) {
var converter = Cc["@mozilla.org/widget/htmlformatconverter;1"].
createInstance(Ci.nsIFormatConverter);
var input = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString);
input.data = html.replace("\n", "<br>", "g");
var output = {};
converter.convert("text/html", input, input.data.length, "text/unicode",
output, {});
if (output.value instanceof Ci.nsISupportsString)
return output.value.data;
return html;
}
function AddonSearchResult(aId) {
this.id = aId;
}
@ -787,6 +809,12 @@ var AddonRepository = {
continue;
}
// Handle case where the wanted string value is html located in text content
if (localName in HTML_KEY_MAP) {
addon[HTML_KEY_MAP[localName]] = convertHTMLToPlainText(this._getTextContent(node));
continue;
}
// Handle case where the wanted integer value is located in text content
if (localName in INTEGER_KEY_MAP) {
let value = parseInt(this._getTextContent(node));

View File

@ -49,9 +49,10 @@
<link>http://localhost:4444/developer2.html</link>
</author>
</authors>
<summary>Test Summary 2</summary>
<description>Test Description 2</description>
<developer_comments>Test Developer Comments 2</developer_comments>
<summary>&lt;h1&gt;Test Summary 2&lt;/h1&gt;&lt;p&gt;paragraph&lt;/p&gt;</summary>
<description>Test Description 2&lt;br&gt;newline</description>
<developer_comments>Test Developer
Comments 2</developer_comments>
<eula>Test EULA 2</eula>
<icon>http://localhost:4444/icon2.png</icon>
<status id="4">Public</status>
@ -128,7 +129,7 @@
</author>
</authors>
<summary> Test Summary 3 </summary>
<description> Test Description 3 </description>
<description> Test Description 3&lt;br&gt;&lt;ul&gt;&lt;li&gt;List item 1&lt;li&gt;List item 2&lt;/ul&gt; </description>
<developer_comments> Test Developer Comments 3 </developer_comments>
<eula> Test EULA 3 </eula>
<icon> http://localhost:4444/icon3.png </icon>

View File

@ -19,10 +19,11 @@
<link>http://localhost:4444/repo/1/secondDeveloper.html</link>
</author>
</authors>
<summary>Repo Add-on 1 - Description</summary>
<description>Repo Add-on 1 - Full Description</description>
<summary>Repo Add-on 1 - Description&lt;br&gt;Second line</summary>
<description>&lt;p&gt;Repo Add-on 1 - Full Description &amp;amp; some extra&lt;/p&gt;</description>
<eula>Repo Add-on 1 - EULA</eula>
<developer_comments>Repo Add-on 1 - Developer Comments</developer_comments>
<developer_comments>Repo Add-on 1
Developer Comments</developer_comments>
<icon>http://localhost:4444/repo/1/icon.png</icon>
<status id="4">Public</status>
<rating>1</rating>

View File

@ -107,9 +107,9 @@ var SEARCH_RESULTS = [{
name: "Test Developer 2",
url: BASE_URL + "/developer2.html"
}],
description: "Test Summary 2",
fullDescription: "Test Description 2",
developerComments: "Test Developer Comments 2",
description: "Test Summary 2\n\nparagraph",
fullDescription: "Test Description 2\nnewline",
developerComments: "Test Developer\nComments 2",
eula: "Test EULA 2",
iconURL: BASE_URL + "/icon2.png",
screenshots: [{
@ -142,7 +142,7 @@ var SEARCH_RESULTS = [{
url: BASE_URL + "/developer2-3.html"
}],
description: "Test Summary 3",
fullDescription: "Test Description 3",
fullDescription: "Test Description 3\n\n List item 1\n List item 2",
developerComments: "Test Developer Comments 3",
eula: "Test EULA 3",
iconURL: BASE_URL + "/icon3.png",

View File

@ -71,9 +71,9 @@ const REPOSITORY_ADDONS = [{
name: "Repo Add-on 1 - Second Developer",
url: BASE_URL + "/repo/1/secondDeveloper.html"
}],
description: "Repo Add-on 1 - Description",
fullDescription: "Repo Add-on 1 - Full Description",
developerComments: "Repo Add-on 1 - Developer Comments",
description: "Repo Add-on 1 - Description\nSecond line",
fullDescription: "Repo Add-on 1 - Full Description & some extra",
developerComments: "Repo Add-on 1\nDeveloper Comments",
eula: "Repo Add-on 1 - EULA",
iconURL: BASE_URL + "/repo/1/icon.png",
homepageURL: BASE_URL + "/repo/1/homepage.html",
@ -202,8 +202,8 @@ const WITH_CACHE = [{
contributors: [{ name: "XPI Add-on 1 - First Contributor" },
{ name: "XPI Add-on 1 - Second Contributor" }],
description: "XPI Add-on 1 - Description",
fullDescription: "Repo Add-on 1 - Full Description",
developerComments: "Repo Add-on 1 - Developer Comments",
fullDescription: "Repo Add-on 1 - Full Description & some extra",
developerComments: "Repo Add-on 1\nDeveloper Comments",
eula: "Repo Add-on 1 - EULA",
iconURL: BASE_URL + "/xpi/1/icon.png",
homepageURL: BASE_URL + "/xpi/1/homepage.html",

View File

@ -582,6 +582,7 @@
#detail-desc {
-moz-margin-start: 6px;
white-space: pre-wrap;
}
#detail-contributions {

View File

@ -618,6 +618,7 @@
/* This is necessary to fix layout issues with multi-line descriptions, see
bug 592712*/
outline: solid transparent;
white-space: pre-wrap;
}
#detail-contributions {

View File

@ -599,6 +599,7 @@
#detail-desc {
-moz-margin-start: 6px;
white-space: pre-wrap;
}
#detail-contributions {