mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-14 23:57:07 +00:00
Escape the five predefined entities to display them as text.
This commit is contained in:
parent
8e9fca9db2
commit
06302e7442
2 changed files with 24 additions and 22 deletions
|
@ -12,10 +12,7 @@ function setup() {
|
|||
var suggestResults = [];
|
||||
for (var i = 0; i < searchResults.length; i++) {
|
||||
var result = searchResults[i];
|
||||
suggestResults.push({
|
||||
content: result.href,
|
||||
description: buildDescription(result)
|
||||
})
|
||||
suggestResults.push(buildSuggestResultItem(result));
|
||||
}
|
||||
|
||||
if (suggestResults.length === 0) {
|
||||
|
@ -24,7 +21,7 @@ function setup() {
|
|||
content: "https://doc.rust-lang.org/stable/std/?search=" + query,
|
||||
description: "Sorry, no Rust official documentation result about <match>" + query
|
||||
+ "</match> found, click here to search on <dim>doc.rust-lang.org</dim>"
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -46,10 +43,24 @@ function navigateToUrl(url) {
|
|||
});
|
||||
}
|
||||
|
||||
function buildDescription(item) {
|
||||
if (item) {
|
||||
return item.displayPath + "<match>" + item.name + "</match>" + " <dim>" + item.desc + "</dim>";
|
||||
} else {
|
||||
return "";
|
||||
// Escape the five predefined entities to display them as text.
|
||||
function escape(text) {
|
||||
text = text || "";
|
||||
return text
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function buildSuggestResultItem(item) {
|
||||
var description = item.displayPath + "<match>" + item.name + "</match>";
|
||||
if (item.desc) {
|
||||
description += " <dim>" + escape(item.desc) + "</dim>";
|
||||
}
|
||||
return {
|
||||
content: item.href,
|
||||
description: description,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,8 +84,7 @@ function buildIndex(rawSearchIndex) {
|
|||
var paths = rawSearchIndex[crate].paths;
|
||||
|
||||
// convert `paths` into an object form
|
||||
var len = paths.length;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
for (var i = 0; i < paths.length; ++i) {
|
||||
paths[i] = {ty: paths[i][0], name: paths[i][1]};
|
||||
}
|
||||
|
||||
|
@ -250,7 +249,6 @@ function execQuery(query) {
|
|||
var contains = paths.slice(0, paths.length > 1 ? paths.length - 1 : 1);
|
||||
|
||||
for (j = 0; j < nSearchWords; ++j) {
|
||||
var lev_distance;
|
||||
var ty = searchIndex[j];
|
||||
if (!ty) {
|
||||
continue;
|
||||
|
@ -270,8 +268,7 @@ function execQuery(query) {
|
|||
var lev = MAX_LEV_DISTANCE + 1;
|
||||
var fullId = generateId(ty);
|
||||
|
||||
if (/*searchWords[j].indexOf(split[i]) > -1 ||*/
|
||||
searchWords[j].indexOf(val) > -1 ||
|
||||
if (searchWords[j].indexOf(val) > -1 ||
|
||||
searchWords[j].replace(/_/g, "").indexOf(val) > -1) {
|
||||
// filter type: ... queries
|
||||
if (typePassesFilter(typeFilter, ty.ty) && results[fullId] === undefined) {
|
||||
|
@ -342,11 +339,6 @@ function sortResults(results) {
|
|||
return a - b;
|
||||
}
|
||||
|
||||
// sort by crate (non-current crate goes later)
|
||||
// a = (aaa.item.crate !== window.currentCrate);
|
||||
// b = (bbb.item.crate !== window.currentCrate);
|
||||
// if (a !== b) { return a - b; }
|
||||
|
||||
// sort by exact match (mismatch goes later)
|
||||
a = (aaa.word !== valLower);
|
||||
b = (bbb.word !== valLower);
|
||||
|
@ -427,8 +419,7 @@ function sortResults(results) {
|
|||
path = result.item.path.toLowerCase(),
|
||||
parent = result.item.parent;
|
||||
|
||||
if (/* isType !== true &&*/
|
||||
validateResult(name, path, split, parent) === false) {
|
||||
if (validateResult(name, path, split, parent) === false) {
|
||||
result.id = -1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue