Skip to content

Commit 184cdce

Browse files
authored
Merge pull request #5932 from dojutsu-user/fix-spacing-bw-results
Fix spacing between the results and add highlight url param
2 parents c4bdddd + 127eb04 commit 184cdce

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

media/css/readthedocs-doc-embed.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,8 @@ div.ethical-footer {
286286
font-size: 14px;
287287
line-height: 20px;
288288
}
289+
290+
/* Margin between the search results */
291+
.rtd_search_hits_spacing {
292+
margin: 10px 0;
293+
}

readthedocs/core/static-src/core/js/doc-embed/search.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ function attach_elastic_search_query(data) {
5050
}
5151

5252
// Creating the result from elements
53-
var link = doc.link + DOCUMENTATION_OPTIONS.FILE_SUFFIX;
54-
var highlight_link = link + "?highlight=" + $.urlencode(query);
53+
var link = doc.link + DOCUMENTATION_OPTIONS.FILE_SUFFIX + "?highlight=" + $.urlencode(query);
5554

56-
var item = $('<a>', {'href': highlight_link});
55+
var item = $('<a>', {'href': link});
5756
item.html(title);
5857
item.find('em').addClass('highlighted');
5958
list_item.append(item);
@@ -170,7 +169,12 @@ function attach_elastic_search_query(data) {
170169

171170
contents.find('em').addClass('highlighted');
172171
list_item.append(contents);
173-
list_item.append($("<br>"));
172+
173+
// Create some spacing between the results.
174+
// Also, don't add this spacing in the last hit.
175+
if (j !== inner_hits.length - 1) {
176+
list_item.append($("<div class='rtd_search_hits_spacing'></div>"));
177+
}
174178
}
175179

176180
Search.output.append(list_item);

readthedocs/core/static/core/js/readthedocs-doc-embed.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readthedocs/templates/search/elastic_search.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ <h3>
186186
{% for inner_hit in result.meta.inner_hits %}
187187
{% if inner_hit.type == 'domains' %}
188188
<p>
189-
<a href="{% doc_url result.project|get_project result.version inner_hit.source.doc_name %}#{{ inner_hit.source.anchor }}">
189+
<a href="{% doc_url result.project|get_project result.version inner_hit.source.doc_name %}?highlight= {{ query }}#{{ inner_hit.source.anchor }}">
190190

191191
{% if inner_hit.source.display_name|length >= 1 %}
192192
({{ inner_hit.source.role_name }}) {{ inner_hit.source.display_name}}
@@ -207,7 +207,7 @@ <h3>
207207

208208
{% elif inner_hit.type == 'sections' %}
209209
<p>
210-
<a href="{% doc_url result.project|get_project result.version result.full_path %}#{{ inner_hit.source.id }}">
210+
<a href="{% doc_url result.project|get_project result.version result.full_path %}?highlight={{ query }}#{{ inner_hit.source.id }}">
211211
{% if inner_hit.highlight|get_key_or_none:"sections.title" %}
212212
{% with section_title=inner_hit.highlight|get_key_or_none:"sections.title" %}
213213
{{ section_title.0|safe }}

0 commit comments

Comments
 (0)