diff --git a/AUTHORS b/AUTHORS
index 8505b644de2..dbe1082a648 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -64,6 +64,7 @@ Other contributors, listed alphabetically, are:
* \T. Powers -- HTML output improvements
* Jeppe Pihl -- literalinclude improvements
* Rob Ruana -- napoleon extension
+* Vince Salvino -- JavaScript search improvements
* Stefan Seefeld -- toctree improvements
* Gregory Szorc -- performance improvements
* Taku Shimizu -- epub3 builder
diff --git a/CHANGES b/CHANGES
index 2de03ba68cf..00a5915cdd6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -20,6 +20,8 @@ Bugs fixed
properly
* #7189: autodoc: classmethod coroutines are not detected
* #7183: intersphinx: ``:attr:`` reference to property is broken
+* (#6244, #6387): Search breaks/hangs when built with ``dirhtml``.
+
Testing
--------
diff --git a/doc/templating.rst b/doc/templating.rst
index 14fb31ed89c..fd0f6b637de 100644
--- a/doc/templating.rst
+++ b/doc/templating.rst
@@ -121,6 +121,17 @@ The following blocks exist in the ``layout.html`` template:
The contents of the document itself. It contains the block "body" where the
individual content is put by subtemplates like ``page.html``.
+ .. note::
+ In order for the built-in JavaScript search to show a page preview on
+ the results page, the document or body content should be wrapped in an
+ HTML element containing the ``role="main"`` attribute. For example:
+
+ .. sourcecode:: html+jinja
+
+
+ {% block document %}{% endblock %}
+
+
`sidebar1` / `sidebar2`
A possible location for a sidebar. `sidebar1` appears before the document
and is empty by default, `sidebar2` after the document and contains the
@@ -427,5 +438,3 @@ are in HTML form), these variables are also available:
* ``includehidden`` (``False`` by default): if true, the TOC tree will also
contain hidden entries.
-
-
diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js
index edef8acf5c1..f4b1c17348a 100644
--- a/sphinx/themes/basic/static/searchtools.js
+++ b/sphinx/themes/basic/static/searchtools.js
@@ -63,6 +63,9 @@ var Search = {
htmlElement.innerHTML = htmlString;
$(htmlElement).find('.headerlink').remove();
docContent = $(htmlElement).find('[role=main]')[0];
+ if(docContent === undefined) {
+ return "";
+ }
return docContent.textContent || docContent.innerText;
},
@@ -245,6 +248,7 @@ var Search = {
if (results.length) {
var item = results.pop();
var listItem = $('');
+ var requestUrl = "";
if (DOCUMENTATION_OPTIONS.BUILDER === 'dirhtml') {
// dirhtml builder
var dirname = item[0] + '/';
@@ -253,15 +257,15 @@ var Search = {
} else if (dirname == 'index/') {
dirname = '';
}
- listItem.append($('').attr('href',
- DOCUMENTATION_OPTIONS.URL_ROOT + dirname +
- highlightstring + item[2]).html(item[1]));
+ requestUrl = DOCUMENTATION_OPTIONS.URL_ROOT + dirname;
+
} else {
// normal html builders
- listItem.append($('').attr('href',
- item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX +
- highlightstring + item[2]).html(item[1]));
+ requestUrl = DOCUMENTATION_OPTIONS.URL_ROOT + item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX;
}
+ listItem.append($('').attr('href',
+ requestUrl +
+ highlightstring + item[2]).html(item[1]));
if (item[3]) {
listItem.append($(' (' + item[3] + ')'));
Search.output.append(listItem);
@@ -269,7 +273,7 @@ var Search = {
displayNextItem();
});
} else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
- $.ajax({url: DOCUMENTATION_OPTIONS.URL_ROOT + item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX,
+ $.ajax({url: requestUrl,
dataType: "text",
complete: function(jqxhr, textstatus) {
var data = jqxhr.responseText;