@@ -4,8 +4,8 @@ pub mod fs;
44mod string;
55pub ( crate ) mod toml_ext;
66use crate :: errors:: Error ;
7- use lazy_static:: lazy_static;
87use log:: error;
8+ use once_cell:: sync:: Lazy ;
99use pulldown_cmark:: { html, CodeBlockKind , CowStr , Event , Options , Parser , Tag } ;
1010use regex:: Regex ;
1111
@@ -21,9 +21,7 @@ pub use self::string::{
2121
2222/// Replaces multiple consecutive whitespace characters with a single space character.
2323pub fn collapse_whitespace ( text : & str ) -> Cow < ' _ , str > {
24- lazy_static ! {
25- static ref RE : Regex = Regex :: new( r"\s\s+" ) . unwrap( ) ;
26- }
24+ static RE : Lazy < Regex > = Lazy :: new ( || Regex :: new ( r"\s\s+" ) . unwrap ( ) ) ;
2725 RE . replace_all ( text, " " )
2826}
2927
@@ -52,9 +50,7 @@ pub fn id_from_content(content: &str) -> String {
5250 let mut content = content. to_string ( ) ;
5351
5452 // Skip any tags or html-encoded stuff
55- lazy_static ! {
56- static ref HTML : Regex = Regex :: new( r"(<.*?>)" ) . unwrap( ) ;
57- }
53+ static HTML : Lazy < Regex > = Lazy :: new ( || Regex :: new ( r"(<.*?>)" ) . unwrap ( ) ) ;
5854 content = HTML . replace_all ( & content, "" ) . into ( ) ;
5955 const REPL_SUB : & [ & str ] = & [ "<" , ">" , "&" , "'" , """ ] ;
6056 for sub in REPL_SUB {
@@ -97,10 +93,9 @@ pub fn unique_id_from_content(content: &str, id_counter: &mut HashMap<String, us
9793/// None. Ideally, print page links would link to anchors on the print page,
9894/// but that is very difficult.
9995fn adjust_links < ' a > ( event : Event < ' a > , path : Option < & Path > ) -> Event < ' a > {
100- lazy_static ! {
101- static ref SCHEME_LINK : Regex = Regex :: new( r"^[a-z][a-z0-9+.-]*:" ) . unwrap( ) ;
102- static ref MD_LINK : Regex = Regex :: new( r"(?P<link>.*)\.md(?P<anchor>#.*)?" ) . unwrap( ) ;
103- }
96+ static SCHEME_LINK : Lazy < Regex > = Lazy :: new ( || Regex :: new ( r"^[a-z][a-z0-9+.-]*:" ) . unwrap ( ) ) ;
97+ static MD_LINK : Lazy < Regex > =
98+ Lazy :: new ( || Regex :: new ( r"(?P<link>.*)\.md(?P<anchor>#.*)?" ) . unwrap ( ) ) ;
10499
105100 fn fix < ' a > ( dest : CowStr < ' a > , path : Option < & Path > ) -> CowStr < ' a > {
106101 if dest. starts_with ( '#' ) {
@@ -153,10 +148,8 @@ fn adjust_links<'a>(event: Event<'a>, path: Option<&Path>) -> Event<'a> {
153148 // There are dozens of HTML tags/attributes that contain paths, so
154149 // feel free to add more tags if desired; these are the only ones I
155150 // care about right now.
156- lazy_static ! {
157- static ref HTML_LINK : Regex =
158- Regex :: new( r#"(<(?:a|img) [^>]*?(?:src|href)=")([^"]+?)""# ) . unwrap( ) ;
159- }
151+ static HTML_LINK : Lazy < Regex > =
152+ Lazy :: new ( || Regex :: new ( r#"(<(?:a|img) [^>]*?(?:src|href)=")([^"]+?)""# ) . unwrap ( ) ) ;
160153
161154 HTML_LINK
162155 . replace_all ( & html, |caps : & regex:: Captures < ' _ > | {
0 commit comments