@@ -763,10 +763,13 @@ fn make_data(
763
763
/// Goes through the rendered HTML, making sure all header tags have
764
764
/// an anchor respectively so people can link to sections directly.
765
765
fn build_header_links ( html : & str ) -> String {
766
- let regex = Regex :: new ( r"<h(\d)>(.*?)</h\d>" ) . unwrap ( ) ;
766
+ lazy_static ! {
767
+ static ref BUILD_HEADER_LINKS : Regex = Regex :: new( r"<h(\d)>(.*?)</h\d>" ) . unwrap( ) ;
768
+ }
769
+
767
770
let mut id_counter = HashMap :: new ( ) ;
768
771
769
- regex
772
+ BUILD_HEADER_LINKS
770
773
. replace_all ( html, |caps : & Captures < ' _ > | {
771
774
let level = caps[ 1 ]
772
775
. parse ( )
@@ -803,8 +806,12 @@ fn insert_link_into_header(
803
806
// ```
804
807
// This function replaces all commas by spaces in the code block classes
805
808
fn fix_code_blocks ( html : & str ) -> String {
806
- let regex = Regex :: new ( r##"<code([^>]+)class="([^"]+)"([^>]*)>"## ) . unwrap ( ) ;
807
- regex
809
+ lazy_static ! {
810
+ static ref FIX_CODE_BLOCKS : Regex =
811
+ Regex :: new( r##"<code([^>]+)class="([^"]+)"([^>]*)>"## ) . unwrap( ) ;
812
+ }
813
+
814
+ FIX_CODE_BLOCKS
808
815
. replace_all ( html, |caps : & Captures < ' _ > | {
809
816
let before = & caps[ 1 ] ;
810
817
let classes = & caps[ 2 ] . replace ( "," , " " ) ;
@@ -825,8 +832,11 @@ fn add_playground_pre(
825
832
playground_config : & Playground ,
826
833
edition : Option < RustEdition > ,
827
834
) -> String {
828
- let regex = Regex :: new ( r##"((?s)<code[^>]?class="([^"]+)".*?>(.*?)</code>)"## ) . unwrap ( ) ;
829
- regex
835
+ lazy_static ! {
836
+ static ref ADD_PLAYGROUND_PRE : Regex =
837
+ Regex :: new( r##"((?s)<code[^>]?class="([^"]+)".*?>(.*?)</code>)"## ) . unwrap( ) ;
838
+ }
839
+ ADD_PLAYGROUND_PRE
830
840
. replace_all ( html, |caps : & Captures < ' _ > | {
831
841
let text = & caps[ 1 ] ;
832
842
let classes = & caps[ 2 ] ;
@@ -890,11 +900,11 @@ fn add_playground_pre(
890
900
. into_owned ( )
891
901
}
892
902
893
- lazy_static ! {
894
- static ref BORING_LINES_REGEX : Regex = Regex :: new( r"^(\s*)#(.?)(.*)$" ) . unwrap( ) ;
895
- }
896
-
897
903
fn hide_lines ( content : & str ) -> String {
904
+ lazy_static ! {
905
+ static ref BORING_LINES_REGEX : Regex = Regex :: new( r"^(\s*)#(.?)(.*)$" ) . unwrap( ) ;
906
+ }
907
+
898
908
let mut result = String :: with_capacity ( content. len ( ) ) ;
899
909
for line in content. lines ( ) {
900
910
if let Some ( caps) = BORING_LINES_REGEX . captures ( line) {
0 commit comments