File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
sphinx/themes/basic/static Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -163,13 +163,19 @@ const Search = {
163163 htmlToText : ( htmlString , anchor ) => {
164164 const htmlElement = new DOMParser ( ) . parseFromString ( htmlString , 'text/html' ) ;
165165 htmlElement . querySelectorAll ( ".headerlink" ) . forEach ( ( el ) => { el . remove ( ) } ) ;
166- let docContent = undefined ;
167- if ( anchor && htmlElement . querySelector ( anchor ) ) {
168- docContent = htmlElement . querySelector ( anchor ) ;
169- } else {
170- docContent = htmlElement . querySelector ( '[role="main"]' ) ;
166+ if ( anchor ) {
167+ const anchorContent = htmlElement . querySelector ( anchor ) ;
168+ if ( anchorContent ) return anchorContent . textContent ;
169+
170+ console . warn (
171+ `Anchor block not found. Sphinx search tries to obtain it via '${ anchor } '. Check your theme or template.`
172+ ) ;
171173 }
174+
175+ // if anchor not specified or not found, fall back to main content
176+ const docContent = htmlElement . querySelector ( '[role="main"]' ) ;
172177 if ( docContent ) return docContent . textContent ;
178+
173179 console . warn (
174180 "Content block not found. Sphinx search tries to obtain it via '[role=main]'. Could you check your theme or template."
175181 ) ;
You can’t perform that action at this time.
0 commit comments