зеркало из https://github.com/mozilla/pjs.git
Bug 595280: AddonRepository should convert HTML to plain text. r=Unfocused, a=blocking-betaN
This commit is contained in:
Родитель
3606bb4b5a
Коммит
af97aca52d
|
@ -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));
|
||||
|
|
|
@ -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><h1>Test Summary 2</h1><p>paragraph</p></summary>
|
||||
<description>Test Description 2<br>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<br><ul><li>List item 1<li>List item 2</ul> </description>
|
||||
<developer_comments> Test Developer Comments 3 </developer_comments>
|
||||
<eula> Test EULA 3 </eula>
|
||||
<icon> http://localhost:4444/icon3.png </icon>
|
||||
|
|
|
@ -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<br>Second line</summary>
|
||||
<description><p>Repo Add-on 1 - Full Description &amp; some extra</p></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>
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -582,6 +582,7 @@
|
|||
|
||||
#detail-desc {
|
||||
-moz-margin-start: 6px;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
#detail-contributions {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -599,6 +599,7 @@
|
|||
|
||||
#detail-desc {
|
||||
-moz-margin-start: 6px;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
#detail-contributions {
|
||||
|
|
Загрузка…
Ссылка в новой задаче