Skip to content

Commit 6aaeee2

Browse files
authored
[search] constraint retrieval for anchored search result summary (#12105)
This is a post-merge adjustments for #11944.
1 parent 16748ae commit 6aaeee2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

sphinx/themes/basic/static/searchtools.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ const Search = {
164164
const htmlElement = new DOMParser().parseFromString(htmlString, 'text/html');
165165
htmlElement.querySelectorAll(".headerlink").forEach((el) => { el.remove() });
166166
if (anchor) {
167-
const anchorContent = htmlElement.querySelector(anchor);
167+
const anchorContent = htmlElement.querySelector(`[role="main"] ${anchor}`);
168168
if (anchorContent) return anchorContent.textContent;
169169

170170
console.warn(
171-
`Anchor block not found. Sphinx search tries to obtain it via '${anchor}'. Check your theme or template.`
171+
`Anchored content block not found. Sphinx search tries to obtain it via DOM query '[role=main] ${anchor}'. Check your theme or template.`
172172
);
173173
}
174174

@@ -177,7 +177,7 @@ const Search = {
177177
if (docContent) return docContent.textContent;
178178

179179
console.warn(
180-
"Content block not found. Sphinx search tries to obtain it via '[role=main]'. Could you check your theme or template."
180+
"Content block not found. Sphinx search tries to obtain it via DOM query '[role=main]'. Check your theme or template."
181181
);
182182
return "";
183183
},

0 commit comments

Comments
 (0)