@@ -697,20 +697,39 @@ function loadCss(cssFileName) {
697
697
}
698
698
} ( ) ) ;
699
699
700
+ window . rustdoc_add_line_numbers_to_examples = ( ) => {
701
+ onEachLazy ( document . getElementsByClassName ( "rust-example-rendered" ) , x => {
702
+ const parent = x . parentNode ;
703
+ const line_numbers = parent . querySelectorAll ( ".line-number" ) ;
704
+ if ( line_numbers . length > 0 ) {
705
+ return ;
706
+ }
707
+ const count = x . textContent . split ( "\n" ) . length ;
708
+ const elems = [ ] ;
709
+ for ( let i = 0 ; i < count ; ++ i ) {
710
+ elems . push ( i + 1 ) ;
711
+ }
712
+ const node = document . createElement ( "pre" ) ;
713
+ addClass ( node , "line-number" ) ;
714
+ node . innerHTML = elems . join ( "\n" ) ;
715
+ parent . insertBefore ( node , x ) ;
716
+ } ) ;
717
+ } ;
718
+
719
+ window . rustdoc_remove_line_numbers_from_examples = ( ) => {
720
+ onEachLazy ( document . getElementsByClassName ( "rust-example-rendered" ) , x => {
721
+ const parent = x . parentNode ;
722
+ const line_numbers = parent . querySelectorAll ( ".line-number" ) ;
723
+ for ( const node of line_numbers ) {
724
+ parent . removeChild ( node ) ;
725
+ }
726
+ } ) ;
727
+ } ;
728
+
700
729
( function ( ) {
701
730
// To avoid checking on "rustdoc-line-numbers" value on every loop...
702
731
if ( getSettingValue ( "line-numbers" ) === "true" ) {
703
- onEachLazy ( document . getElementsByClassName ( "rust-example-rendered" ) , x => {
704
- const count = x . textContent . split ( "\n" ) . length ;
705
- const elems = [ ] ;
706
- for ( let i = 0 ; i < count ; ++ i ) {
707
- elems . push ( i + 1 ) ;
708
- }
709
- const node = document . createElement ( "pre" ) ;
710
- addClass ( node , "line-number" ) ;
711
- node . innerHTML = elems . join ( "\n" ) ;
712
- x . parentNode . insertBefore ( node , x ) ;
713
- } ) ;
732
+ window . rustdoc_add_line_numbers_to_examples ( ) ;
714
733
}
715
734
} ( ) ) ;
716
735
0 commit comments