Auto merge of #20221 - liigo:rustdoc-sidebar-tooltips-v3, r=alexcrichton
This pull request add tooltips to most links of sidebar. The tooltips display "summary line" of items' document. Some lengthy/annoying raw markdown code are eliminated, such as links and headers. - `[Rust](http://rust-lang.org)` displays as `Rust` (no URLs) - `# header` displays as `header` (no `#`s) Some inline spans, e.g. ``` `code` ``` and ```*emphasis*```, are kept as they are, for better readable. I've make sure `&` `'` `"` `<` and `>` are properly displayed in tooltips, for example, `&'a Option<T>`. Online preview: http://liigo.com/tmp/tooltips/std/index.html @alexcrichton @steveklabnik since you have reviewed my previous ([v1](https://github.com/rust-lang/rust/pull/13014),[v2](https://github.com/rust-lang/rust/pull/16448)) PRs of this serise, which have been closed for technical reasons. Thank you.
This commit is contained in:
@@ -668,6 +668,15 @@
|
||||
search();
|
||||
}
|
||||
|
||||
function plainSummaryLine(markdown) {
|
||||
var str = markdown.replace(/\n/g, ' ')
|
||||
str = str.replace(/'/g, "\'")
|
||||
str = str.replace(/^#+? (.+?)/, "$1")
|
||||
str = str.replace(/\[(.*?)\]\(.*?\)/g, "$1")
|
||||
str = str.replace(/\[(.*?)\]\[.*?\]/g, "$1")
|
||||
return str;
|
||||
}
|
||||
|
||||
index = buildIndex(rawSearchIndex);
|
||||
startSearch();
|
||||
|
||||
@@ -688,8 +697,10 @@
|
||||
if (crates[i] == window.currentCrate) {
|
||||
klass += ' current';
|
||||
}
|
||||
var desc = rawSearchIndex[crates[i]].items[0][3];
|
||||
div.append($('<a>', {'href': '../' + crates[i] + '/index.html',
|
||||
'class': klass}).text(crates[i]));
|
||||
'title': plainSummaryLine(desc),
|
||||
'class': klass}).text(crates[i]));
|
||||
}
|
||||
sidebar.append(div);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user