@@ -892,15 +892,15 @@ fn fix_code_blocks(html: &str) -> String {
892
892
. into_owned ( )
893
893
}
894
894
895
+ static CODE_BLOCK_RE : Lazy < Regex > =
896
+ Lazy :: new ( || Regex :: new ( r##"((?s)<code[^>]?class="([^"]+)".*?>(.*?)</code>)"## ) . unwrap ( ) ) ;
897
+
895
898
fn add_playground_pre (
896
899
html : & str ,
897
900
playground_config : & Playground ,
898
901
edition : Option < RustEdition > ,
899
902
) -> String {
900
- static ADD_PLAYGROUND_PRE : Lazy < Regex > =
901
- Lazy :: new ( || Regex :: new ( r##"((?s)<code[^>]?class="([^"]+)".*?>(.*?)</code>)"## ) . unwrap ( ) ) ;
902
-
903
- ADD_PLAYGROUND_PRE
903
+ CODE_BLOCK_RE
904
904
. replace_all ( html, |caps : & Captures < ' _ > | {
905
905
let text = & caps[ 1 ] ;
906
906
let classes = & caps[ 2 ] ;
@@ -958,11 +958,12 @@ fn add_playground_pre(
958
958
. into_owned ( )
959
959
}
960
960
961
+ /// Modifies all `<code>` blocks to convert "hidden" lines and to wrap them in
962
+ /// a `<span class="boring">`.
961
963
fn hide_lines ( html : & str , code_config : & Code ) -> String {
962
- let regex = Regex :: new ( r##"((?s)<code[^>]?class="([^"]+)".*?>(.*?)</code>)"## ) . unwrap ( ) ;
963
964
let language_regex = Regex :: new ( r"\blanguage-(\w+)\b" ) . unwrap ( ) ;
964
965
let hidelines_regex = Regex :: new ( r"\bhidelines=(\S+)" ) . unwrap ( ) ;
965
- regex
966
+ CODE_BLOCK_RE
966
967
. replace_all ( html, |caps : & Captures < ' _ > | {
967
968
let text = & caps[ 1 ] ;
968
969
let classes = & caps[ 2 ] ;
@@ -981,13 +982,9 @@ fn hide_lines(html: &str, code_config: &Code) -> String {
981
982
Some ( capture) => Some ( & capture[ 1 ] ) ,
982
983
None => {
983
984
// Then look up the prefix by language
984
- let language_capture = language_regex. captures ( classes) ;
985
- match & language_capture {
986
- Some ( capture) => {
987
- code_config. hidelines . get ( & capture[ 1 ] ) . map ( |p| p. as_str ( ) )
988
- }
989
- None => None ,
990
- }
985
+ language_regex. captures ( classes) . and_then ( |capture| {
986
+ code_config. hidelines . get ( & capture[ 1 ] ) . map ( |p| p. as_str ( ) )
987
+ } )
991
988
}
992
989
} ;
993
990
0 commit comments