11/* Highlighting utilities for Sphinx HTML documentation. */
22"use strict" ;
33
4- const SPHINX_HIGHLIGHT_ENABLED = true ;
4+ const SPHINX_HIGHLIGHT_ENABLED = true
55
66/**
77 * highlight a given string on a node by wrapping it in
@@ -13,9 +13,9 @@ const _highlight = (node, addItems, text, className) => {
1313 const parent = node . parentNode ;
1414 const pos = val . toLowerCase ( ) . indexOf ( text ) ;
1515 if (
16- pos >= 0
17- && ! parent . classList . contains ( className )
18- && ! parent . classList . contains ( "nohighlight" )
16+ pos >= 0 &&
17+ ! parent . classList . contains ( className ) &&
18+ ! parent . classList . contains ( "nohighlight" )
1919 ) {
2020 let span ;
2121
@@ -30,7 +30,13 @@ const _highlight = (node, addItems, text, className) => {
3030
3131 span . appendChild ( document . createTextNode ( val . substr ( pos , text . length ) ) ) ;
3232 const rest = document . createTextNode ( val . substr ( pos + text . length ) ) ;
33- parent . insertBefore ( span , parent . insertBefore ( rest , node . nextSibling ) ) ;
33+ parent . insertBefore (
34+ span ,
35+ parent . insertBefore (
36+ rest ,
37+ node . nextSibling
38+ )
39+ ) ;
3440 node . nodeValue = val . substr ( 0 , pos ) ;
3541 /* There may be more occurrences of search term in this node. So call this
3642 * function recursively on the remaining fragment.
@@ -40,7 +46,7 @@ const _highlight = (node, addItems, text, className) => {
4046 if ( isInSVG ) {
4147 const rect = document . createElementNS (
4248 "http://www.w3.org/2000/svg" ,
43- "rect" ,
49+ "rect"
4450 ) ;
4551 const bbox = parent . getBBox ( ) ;
4652 rect . x . baseVal . value = bbox . x ;
@@ -59,39 +65,33 @@ const _highlightText = (thisNode, text, className) => {
5965 let addItems = [ ] ;
6066 _highlight ( thisNode , addItems , text , className ) ;
6167 addItems . forEach ( ( obj ) =>
62- obj . parent . insertAdjacentElement ( "beforebegin" , obj . target ) ,
68+ obj . parent . insertAdjacentElement ( "beforebegin" , obj . target )
6369 ) ;
6470} ;
6571
6672/**
6773 * Small JavaScript module for the documentation.
6874 */
6975const SphinxHighlight = {
76+
7077 /**
7178 * highlight the search words provided in localstorage in the text
7279 */
7380 highlightSearchWords : ( ) => {
74- if ( ! SPHINX_HIGHLIGHT_ENABLED ) return ; // bail if no highlight
81+ if ( ! SPHINX_HIGHLIGHT_ENABLED ) return ; // bail if no highlight
7582
7683 // get and clear terms from localstorage
7784 const url = new URL ( window . location ) ;
7885 const highlight =
79- localStorage . getItem ( "sphinx_highlight_terms" )
80- || url . searchParams . get ( "highlight" )
81- || "" ;
82- localStorage . removeItem ( "sphinx_highlight_terms" ) ;
83- // Update history only if '?highlight' is present; otherwise it
84- // clears text fragments (not set in window.location by the browser)
85- if ( url . searchParams . has ( "highlight" ) ) {
86- url . searchParams . delete ( "highlight" ) ;
87- window . history . replaceState ( { } , "" , url ) ;
88- }
86+ localStorage . getItem ( "sphinx_highlight_terms" )
87+ || url . searchParams . get ( "highlight" )
88+ || "" ;
89+ localStorage . removeItem ( "sphinx_highlight_terms" )
90+ url . searchParams . delete ( "highlight" ) ;
91+ window . history . replaceState ( { } , "" , url ) ;
8992
9093 // get individual terms from highlight string
91- const terms = highlight
92- . toLowerCase ( )
93- . split ( / \s + / )
94- . filter ( ( x ) => x ) ;
94+ const terms = highlight . toLowerCase ( ) . split ( / \s + / ) . filter ( x => x ) ;
9595 if ( terms . length === 0 ) return ; // nothing to do
9696
9797 // There should never be more than one element matching "div.body"
@@ -107,11 +107,11 @@ const SphinxHighlight = {
107107 document
108108 . createRange ( )
109109 . createContextualFragment (
110- '<p class="highlight-link">'
111- + '<a href="javascript:SphinxHighlight.hideSearchWords()">'
112- + _ ( "Hide Search Matches" )
113- + "</a></p>" ,
114- ) ,
110+ '<p class="highlight-link">' +
111+ '<a href="javascript:SphinxHighlight.hideSearchWords()">' +
112+ _ ( "Hide Search Matches" ) +
113+ "</a></p>"
114+ )
115115 ) ;
116116 } ,
117117
@@ -125,7 +125,7 @@ const SphinxHighlight = {
125125 document
126126 . querySelectorAll ( "span.highlighted" )
127127 . forEach ( ( el ) => el . classList . remove ( "highlighted" ) ) ;
128- localStorage . removeItem ( "sphinx_highlight_terms" ) ;
128+ localStorage . removeItem ( "sphinx_highlight_terms" )
129129 } ,
130130
131131 initEscapeListener : ( ) => {
@@ -134,15 +134,10 @@ const SphinxHighlight = {
134134
135135 document . addEventListener ( "keydown" , ( event ) => {
136136 // bail for input elements
137- if ( BLACKLISTED_KEY_CONTROL_ELEMENTS . has ( document . activeElement . tagName ) )
138- return ;
137+ if ( BLACKLISTED_KEY_CONTROL_ELEMENTS . has ( document . activeElement . tagName ) ) return ;
139138 // bail with special keys
140- if ( event . shiftKey || event . altKey || event . ctrlKey || event . metaKey )
141- return ;
142- if (
143- DOCUMENTATION_OPTIONS . ENABLE_SEARCH_SHORTCUTS
144- && event . key === "Escape"
145- ) {
139+ if ( event . shiftKey || event . altKey || event . ctrlKey || event . metaKey ) return ;
140+ if ( DOCUMENTATION_OPTIONS . ENABLE_SEARCH_SHORTCUTS && ( event . key === "Escape" ) ) {
146141 SphinxHighlight . hideSearchWords ( ) ;
147142 event . preventDefault ( ) ;
148143 }
0 commit comments