@@ -138,6 +138,13 @@ function onEachLazy(lazyArray, func) {
138138 }
139139}
140140
141+ function highlightIfNeeded ( elem ) {
142+ onEachLazy ( elem . querySelectorAll ( "pre > code.language-rust:not(.highlighted)" ) , el => {
143+ hljs . highlightElement ( el )
144+ el . classList . add ( "highlighted" ) ;
145+ } ) ;
146+ }
147+
141148function expandLintId ( lintId ) {
142149 searchState . inputElem . value = lintId ;
143150 searchState . filterLints ( ) ;
@@ -146,7 +153,7 @@ function expandLintId(lintId) {
146153 const lintElem = document . getElementById ( lintId ) ;
147154 const isCollapsed = lintElem . classList . remove ( "collapsed" ) ;
148155 lintElem . querySelector ( ".label-doc-folding" ) . innerText = "-" ;
149- onEachLazy ( lintElem . querySelectorAll ( "pre > code.language-rust" ) , el => hljs . highlightElement ( el ) ) ;
156+ highlightIfNeeded ( lintElem ) ;
150157}
151158
152159// Show details for one lint
@@ -160,7 +167,7 @@ function expandLint(lintId) {
160167 const lintElem = document . getElementById ( lintId ) ;
161168 const isCollapsed = lintElem . classList . toggle ( "collapsed" ) ;
162169 lintElem . querySelector ( ".label-doc-folding" ) . innerText = isCollapsed ? "+" : "-" ;
163- onEachLazy ( lintElem . querySelectorAll ( "pre > code.language-rust" ) , el => hljs . highlightElement ( el ) ) ;
170+ highlightIfNeeded ( lintElem ) ;
164171}
165172
166173function copyToClipboard ( event ) {
@@ -198,7 +205,10 @@ function handleBlur(event, elementId) {
198205function toggleExpansion ( expand ) {
199206 onEachLazy (
200207 document . querySelectorAll ( "article" ) ,
201- expand ? el => el . classList . remove ( "collapsed" ) : el => el . classList . add ( "collapsed" ) ,
208+ expand ? el => {
209+ el . classList . remove ( "collapsed" ) ;
210+ highlightIfNeeded ( el ) ;
211+ } : el => el . classList . add ( "collapsed" ) ,
202212 ) ;
203213}
204214
0 commit comments