mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #4022 from TimKam/1618-make-search-results-reader-friendly
#1618 make search results reader friendly
This commit is contained in:
8
CHANGES
8
CHANGES
@@ -12,6 +12,14 @@ Deprecated
|
||||
|
||||
Features added
|
||||
--------------
|
||||
* #1618: The search results preview of generated HTML documentation is
|
||||
reader-friendlier: instead of showing the snippets as raw reStructuredText
|
||||
markup, Sphinx now renders the corresponding HTML. This means the Sphinx
|
||||
extension `Sphinx: pretty search results`__ is no longer necessary. Note that
|
||||
changes to the search function of your custom or 3rd-pary HTML template might
|
||||
overwrite this improvement.
|
||||
|
||||
__ https://github.com/sphinx-contrib/sphinx-pretty-searchresults
|
||||
|
||||
* #4182: autodoc: Support :confval:`suppress_warnings`
|
||||
|
||||
|
@@ -1108,12 +1108,6 @@ that use Sphinx's HTMLWriter class.
|
||||
If true, the reST sources are included in the HTML build as
|
||||
:file:`_sources/{name}`. The default is ``True``.
|
||||
|
||||
.. warning::
|
||||
|
||||
If this config value is set to ``False``, the JavaScript search function
|
||||
will only display the titles of matching documents, and no excerpt from
|
||||
the matching contents.
|
||||
|
||||
.. confval:: html_show_sourcelink
|
||||
|
||||
If true (and :confval:`html_copy_source` is true as well), links to the
|
||||
|
@@ -56,6 +56,14 @@ var Search = {
|
||||
_queued_query : null,
|
||||
_pulse_status : -1,
|
||||
|
||||
htmlToText : function(htmlString) {
|
||||
var htmlElement = document.createElement('span');
|
||||
htmlElement.innerHTML = htmlString;
|
||||
$(htmlElement).find('.headerlink').remove();
|
||||
docContent = $(htmlElement).find('[role=main]')[0];
|
||||
return docContent.textContent || docContent.innerText;
|
||||
},
|
||||
|
||||
init : function() {
|
||||
var params = $.getQueryParameters();
|
||||
if (params.q) {
|
||||
@@ -260,11 +268,7 @@ var Search = {
|
||||
displayNextItem();
|
||||
});
|
||||
} else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
|
||||
var suffix = DOCUMENTATION_OPTIONS.SOURCELINK_SUFFIX;
|
||||
if (suffix === undefined) {
|
||||
suffix = '.txt';
|
||||
}
|
||||
$.ajax({url: DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/' + item[5] + (item[5].slice(-suffix.length) === suffix ? '' : suffix),
|
||||
$.ajax({url: DOCUMENTATION_OPTIONS.URL_ROOT + item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX,
|
||||
dataType: "text",
|
||||
complete: function(jqxhr, textstatus) {
|
||||
var data = jqxhr.responseText;
|
||||
@@ -457,7 +461,8 @@ var Search = {
|
||||
* words. the first one is used to find the occurrence, the
|
||||
* latter for highlighting it.
|
||||
*/
|
||||
makeSearchSummary : function(text, keywords, hlwords) {
|
||||
makeSearchSummary : function(htmlText, keywords, hlwords) {
|
||||
var text = Search.htmlToText(htmlText);
|
||||
var textLower = text.toLowerCase();
|
||||
var start = 0;
|
||||
$.each(keywords, function() {
|
||||
|
Reference in New Issue
Block a user