summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2022-01-17 01:44:42 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2022-01-17 01:44:42 +0900
commit72bb5c998f780839e0b16b8b2d4997cd04797afd (patch)
tree11444b73e0dd5781f75c89e2106685bece6e22fb
parentbd55cce6e6366804fb1dc5e516d11a98e00e4c46 (diff)
downloadsphinx-git-72bb5c998f780839e0b16b8b2d4997cd04797afd.tar.gz
Close #9456: html search: Add a config variable; html_show_search_summary
refs: #9494
-rw-r--r--CHANGES3
-rw-r--r--doc/usage/configuration.rst7
-rw-r--r--sphinx/builders/html/__init__.py2
-rw-r--r--sphinx/themes/basic/static/documentation_options.js_t3
-rw-r--r--sphinx/themes/basic/static/searchtools.js4
5 files changed, 16 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 2ce9ac366..931c0e0dc 100644
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,9 @@ Deprecated
Features added
--------------
+* #9494, #9456: html search: Add a config variable
+ :confval:`html_show_search_summary` to enable/disable the search summaries
+
Bugs fixed
----------
diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst
index 0254d2dbd..737e22823 100644
--- a/doc/usage/configuration.rst
+++ b/doc/usage/configuration.rst
@@ -1351,6 +1351,13 @@ that use Sphinx's HTMLWriter class.
.. versionadded:: 1.0
+.. confval:: html_show_search_summary
+
+ If true, the text around the keyword is shown as summary of each search result.
+ Default is ``True``.
+
+ .. versionadded:: 4.5
+
.. confval:: html_show_sphinx
If true, "Created using Sphinx" is shown in the HTML footer. Default is
diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py
index 58fee87f9..9f9c17b3d 100644
--- a/sphinx/builders/html/__init__.py
+++ b/sphinx/builders/html/__init__.py
@@ -509,6 +509,7 @@ class StandaloneHTMLBuilder(Builder):
'docstitle': self.config.html_title,
'shorttitle': self.config.html_short_title,
'show_copyright': self.config.html_show_copyright,
+ 'show_search_summary': self.config.html_show_search_summary,
'show_sphinx': self.config.html_show_sphinx,
'has_source': self.config.html_copy_source,
'show_source': self.config.html_show_sourcelink,
@@ -1340,6 +1341,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
app.add_config_value('html_file_suffix', None, 'html', [str])
app.add_config_value('html_link_suffix', None, 'html', [str])
app.add_config_value('html_show_copyright', True, 'html')
+ app.add_config_value('html_show_search_summary', True, 'html')
app.add_config_value('html_show_sphinx', True, 'html')
app.add_config_value('html_context', {}, 'html')
app.add_config_value('html_output_encoding', 'utf-8', 'html')
diff --git a/sphinx/themes/basic/static/documentation_options.js_t b/sphinx/themes/basic/static/documentation_options.js_t
index 8afaac2f8..5f4cca454 100644
--- a/sphinx/themes/basic/static/documentation_options.js_t
+++ b/sphinx/themes/basic/static/documentation_options.js_t
@@ -8,5 +8,6 @@ var DOCUMENTATION_OPTIONS = {
LINK_SUFFIX: '{{ link_suffix }}',
HAS_SOURCE: {{ has_source|lower }},
SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}',
- NAVIGATION_WITH_KEYS: {{ 'true' if theme_navigation_with_keys|tobool else 'false'}}
+ NAVIGATION_WITH_KEYS: {{ 'true' if theme_navigation_with_keys|tobool else 'false'}},
+ SHOW_SEARCH_SUMMARY: {{ 'true' if show_search_summary else 'false' }}
};
diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js
index 2d7785937..5b48b5d1b 100644
--- a/sphinx/themes/basic/static/searchtools.js
+++ b/sphinx/themes/basic/static/searchtools.js
@@ -276,7 +276,7 @@ var Search = {
setTimeout(function() {
displayNextItem();
}, 5);
- } else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
+ } else if (DOCUMENTATION_OPTIONS.SHOW_SEARCH_SUMMARY) {
$.ajax({url: requestUrl,
dataType: "text",
complete: function(jqxhr, textstatus) {
@@ -293,7 +293,7 @@ var Search = {
}, 5);
}});
} else {
- // no source available, just display title
+ // just display title
Search.output.append(listItem);
setTimeout(function() {
displayNextItem();