зеркало из https://github.com/mozilla/gecko-dev.git
Bug 595280: AddonRepository should convert HTML to plain text. r=Unfocused, a=blocking-betaN
This commit is contained in:
Родитель
c03962c464
Коммит
bdd6dcb091
|
@ -91,15 +91,20 @@ const PROP_MULTI = ["developers", "screenshots"]
|
||||||
const STRING_KEY_MAP = {
|
const STRING_KEY_MAP = {
|
||||||
name: "name",
|
name: "name",
|
||||||
version: "version",
|
version: "version",
|
||||||
summary: "description",
|
|
||||||
description: "fullDescription",
|
|
||||||
developer_comments: "developerComments",
|
|
||||||
eula: "eula",
|
|
||||||
icon: "iconURL",
|
icon: "iconURL",
|
||||||
homepage: "homepageURL",
|
homepage: "homepageURL",
|
||||||
support: "supportURL"
|
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
|
// A map between XML keys to AddonSearchResult keys for integer values
|
||||||
// that require no extra parsing from XML
|
// that require no extra parsing from XML
|
||||||
const INTEGER_KEY_MAP = {
|
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) {
|
function AddonSearchResult(aId) {
|
||||||
this.id = aId;
|
this.id = aId;
|
||||||
}
|
}
|
||||||
|
@ -787,6 +809,12 @@ var AddonRepository = {
|
||||||
continue;
|
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
|
// Handle case where the wanted integer value is located in text content
|
||||||
if (localName in INTEGER_KEY_MAP) {
|
if (localName in INTEGER_KEY_MAP) {
|
||||||
let value = parseInt(this._getTextContent(node));
|
let value = parseInt(this._getTextContent(node));
|
||||||
|
|
|
@ -49,9 +49,10 @@
|
||||||
<link>http://localhost:4444/developer2.html</link>
|
<link>http://localhost:4444/developer2.html</link>
|
||||||
</author>
|
</author>
|
||||||
</authors>
|
</authors>
|
||||||
<summary>Test Summary 2</summary>
|
<summary><h1>Test Summary 2</h1><p>paragraph</p></summary>
|
||||||
<description>Test Description 2</description>
|
<description>Test Description 2<br>newline</description>
|
||||||
<developer_comments>Test Developer Comments 2</developer_comments>
|
<developer_comments>Test Developer
|
||||||
|
Comments 2</developer_comments>
|
||||||
<eula>Test EULA 2</eula>
|
<eula>Test EULA 2</eula>
|
||||||
<icon>http://localhost:4444/icon2.png</icon>
|
<icon>http://localhost:4444/icon2.png</icon>
|
||||||
<status id="4">Public</status>
|
<status id="4">Public</status>
|
||||||
|
@ -128,7 +129,7 @@
|
||||||
</author>
|
</author>
|
||||||
</authors>
|
</authors>
|
||||||
<summary> Test Summary 3 </summary>
|
<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>
|
<developer_comments> Test Developer Comments 3 </developer_comments>
|
||||||
<eula> Test EULA 3 </eula>
|
<eula> Test EULA 3 </eula>
|
||||||
<icon> http://localhost:4444/icon3.png </icon>
|
<icon> http://localhost:4444/icon3.png </icon>
|
||||||
|
|
|
@ -19,10 +19,11 @@
|
||||||
<link>http://localhost:4444/repo/1/secondDeveloper.html</link>
|
<link>http://localhost:4444/repo/1/secondDeveloper.html</link>
|
||||||
</author>
|
</author>
|
||||||
</authors>
|
</authors>
|
||||||
<summary>Repo Add-on 1 - Description</summary>
|
<summary>Repo Add-on 1 - Description<br>Second line</summary>
|
||||||
<description>Repo Add-on 1 - Full Description</description>
|
<description><p>Repo Add-on 1 - Full Description &amp; some extra</p></description>
|
||||||
<eula>Repo Add-on 1 - EULA</eula>
|
<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>
|
<icon>http://localhost:4444/repo/1/icon.png</icon>
|
||||||
<status id="4">Public</status>
|
<status id="4">Public</status>
|
||||||
<rating>1</rating>
|
<rating>1</rating>
|
||||||
|
|
|
@ -107,9 +107,9 @@ var SEARCH_RESULTS = [{
|
||||||
name: "Test Developer 2",
|
name: "Test Developer 2",
|
||||||
url: BASE_URL + "/developer2.html"
|
url: BASE_URL + "/developer2.html"
|
||||||
}],
|
}],
|
||||||
description: "Test Summary 2",
|
description: "Test Summary 2\n\nparagraph",
|
||||||
fullDescription: "Test Description 2",
|
fullDescription: "Test Description 2\nnewline",
|
||||||
developerComments: "Test Developer Comments 2",
|
developerComments: "Test Developer\nComments 2",
|
||||||
eula: "Test EULA 2",
|
eula: "Test EULA 2",
|
||||||
iconURL: BASE_URL + "/icon2.png",
|
iconURL: BASE_URL + "/icon2.png",
|
||||||
screenshots: [{
|
screenshots: [{
|
||||||
|
@ -142,7 +142,7 @@ var SEARCH_RESULTS = [{
|
||||||
url: BASE_URL + "/developer2-3.html"
|
url: BASE_URL + "/developer2-3.html"
|
||||||
}],
|
}],
|
||||||
description: "Test Summary 3",
|
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",
|
developerComments: "Test Developer Comments 3",
|
||||||
eula: "Test EULA 3",
|
eula: "Test EULA 3",
|
||||||
iconURL: BASE_URL + "/icon3.png",
|
iconURL: BASE_URL + "/icon3.png",
|
||||||
|
|
|
@ -71,9 +71,9 @@ const REPOSITORY_ADDONS = [{
|
||||||
name: "Repo Add-on 1 - Second Developer",
|
name: "Repo Add-on 1 - Second Developer",
|
||||||
url: BASE_URL + "/repo/1/secondDeveloper.html"
|
url: BASE_URL + "/repo/1/secondDeveloper.html"
|
||||||
}],
|
}],
|
||||||
description: "Repo Add-on 1 - Description",
|
description: "Repo Add-on 1 - Description\nSecond line",
|
||||||
fullDescription: "Repo Add-on 1 - Full Description",
|
fullDescription: "Repo Add-on 1 - Full Description & some extra",
|
||||||
developerComments: "Repo Add-on 1 - Developer Comments",
|
developerComments: "Repo Add-on 1\nDeveloper Comments",
|
||||||
eula: "Repo Add-on 1 - EULA",
|
eula: "Repo Add-on 1 - EULA",
|
||||||
iconURL: BASE_URL + "/repo/1/icon.png",
|
iconURL: BASE_URL + "/repo/1/icon.png",
|
||||||
homepageURL: BASE_URL + "/repo/1/homepage.html",
|
homepageURL: BASE_URL + "/repo/1/homepage.html",
|
||||||
|
@ -202,8 +202,8 @@ const WITH_CACHE = [{
|
||||||
contributors: [{ name: "XPI Add-on 1 - First Contributor" },
|
contributors: [{ name: "XPI Add-on 1 - First Contributor" },
|
||||||
{ name: "XPI Add-on 1 - Second Contributor" }],
|
{ name: "XPI Add-on 1 - Second Contributor" }],
|
||||||
description: "XPI Add-on 1 - Description",
|
description: "XPI Add-on 1 - Description",
|
||||||
fullDescription: "Repo Add-on 1 - Full Description",
|
fullDescription: "Repo Add-on 1 - Full Description & some extra",
|
||||||
developerComments: "Repo Add-on 1 - Developer Comments",
|
developerComments: "Repo Add-on 1\nDeveloper Comments",
|
||||||
eula: "Repo Add-on 1 - EULA",
|
eula: "Repo Add-on 1 - EULA",
|
||||||
iconURL: BASE_URL + "/xpi/1/icon.png",
|
iconURL: BASE_URL + "/xpi/1/icon.png",
|
||||||
homepageURL: BASE_URL + "/xpi/1/homepage.html",
|
homepageURL: BASE_URL + "/xpi/1/homepage.html",
|
||||||
|
|
|
@ -582,6 +582,7 @@
|
||||||
|
|
||||||
#detail-desc {
|
#detail-desc {
|
||||||
-moz-margin-start: 6px;
|
-moz-margin-start: 6px;
|
||||||
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
#detail-contributions {
|
#detail-contributions {
|
||||||
|
|
|
@ -618,6 +618,7 @@
|
||||||
/* This is necessary to fix layout issues with multi-line descriptions, see
|
/* This is necessary to fix layout issues with multi-line descriptions, see
|
||||||
bug 592712*/
|
bug 592712*/
|
||||||
outline: solid transparent;
|
outline: solid transparent;
|
||||||
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
#detail-contributions {
|
#detail-contributions {
|
||||||
|
|
|
@ -599,6 +599,7 @@
|
||||||
|
|
||||||
#detail-desc {
|
#detail-desc {
|
||||||
-moz-margin-start: 6px;
|
-moz-margin-start: 6px;
|
||||||
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
#detail-contributions {
|
#detail-contributions {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче