diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /vendor/mdbook/src/utils | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/mdbook/src/utils')
-rw-r--r-- | vendor/mdbook/src/utils/fs.rs | 1 | ||||
-rw-r--r-- | vendor/mdbook/src/utils/mod.rs | 26 | ||||
-rw-r--r-- | vendor/mdbook/src/utils/string.rs | 9 |
3 files changed, 16 insertions, 20 deletions
diff --git a/vendor/mdbook/src/utils/fs.rs b/vendor/mdbook/src/utils/fs.rs index a933d548a..0d6f38374 100644 --- a/vendor/mdbook/src/utils/fs.rs +++ b/vendor/mdbook/src/utils/fs.rs @@ -1,4 +1,5 @@ use crate::errors::*; +use log::{debug, trace}; use std::convert::Into; use std::fs::{self, File}; use std::io::Write; diff --git a/vendor/mdbook/src/utils/mod.rs b/vendor/mdbook/src/utils/mod.rs index a205633f9..9f67deda7 100644 --- a/vendor/mdbook/src/utils/mod.rs +++ b/vendor/mdbook/src/utils/mod.rs @@ -4,9 +4,10 @@ pub mod fs; mod string; pub(crate) mod toml_ext; use crate::errors::Error; -use regex::Regex; - +use log::error; +use once_cell::sync::Lazy; use pulldown_cmark::{html, CodeBlockKind, CowStr, Event, Options, Parser, Tag}; +use regex::Regex; use std::borrow::Cow; use std::collections::HashMap; @@ -20,9 +21,7 @@ pub use self::string::{ /// Replaces multiple consecutive whitespace characters with a single space character. pub fn collapse_whitespace(text: &str) -> Cow<'_, str> { - lazy_static! { - static ref RE: Regex = Regex::new(r"\s\s+").unwrap(); - } + static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"\s\s+").unwrap()); RE.replace_all(text, " ") } @@ -51,9 +50,7 @@ pub fn id_from_content(content: &str) -> String { let mut content = content.to_string(); // Skip any tags or html-encoded stuff - lazy_static! { - static ref HTML: Regex = Regex::new(r"(<.*?>)").unwrap(); - } + static HTML: Lazy<Regex> = Lazy::new(|| Regex::new(r"(<.*?>)").unwrap()); content = HTML.replace_all(&content, "").into(); const REPL_SUB: &[&str] = &["<", ">", "&", "'", """]; for sub in REPL_SUB { @@ -96,10 +93,9 @@ pub fn unique_id_from_content(content: &str, id_counter: &mut HashMap<String, us /// None. Ideally, print page links would link to anchors on the print page, /// but that is very difficult. fn adjust_links<'a>(event: Event<'a>, path: Option<&Path>) -> Event<'a> { - lazy_static! { - static ref SCHEME_LINK: Regex = Regex::new(r"^[a-z][a-z0-9+.-]*:").unwrap(); - static ref MD_LINK: Regex = Regex::new(r"(?P<link>.*)\.md(?P<anchor>#.*)?").unwrap(); - } + static SCHEME_LINK: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[a-z][a-z0-9+.-]*:").unwrap()); + static MD_LINK: Lazy<Regex> = + Lazy::new(|| Regex::new(r"(?P<link>.*)\.md(?P<anchor>#.*)?").unwrap()); fn fix<'a>(dest: CowStr<'a>, path: Option<&Path>) -> CowStr<'a> { if dest.starts_with('#') { @@ -152,10 +148,8 @@ fn adjust_links<'a>(event: Event<'a>, path: Option<&Path>) -> Event<'a> { // There are dozens of HTML tags/attributes that contain paths, so // feel free to add more tags if desired; these are the only ones I // care about right now. - lazy_static! { - static ref HTML_LINK: Regex = - Regex::new(r#"(<(?:a|img) [^>]*?(?:src|href)=")([^"]+?)""#).unwrap(); - } + static HTML_LINK: Lazy<Regex> = + Lazy::new(|| Regex::new(r#"(<(?:a|img) [^>]*?(?:src|href)=")([^"]+?)""#).unwrap()); HTML_LINK .replace_all(&html, |caps: ®ex::Captures<'_>| { diff --git a/vendor/mdbook/src/utils/string.rs b/vendor/mdbook/src/utils/string.rs index 97485d7b6..6dafe2603 100644 --- a/vendor/mdbook/src/utils/string.rs +++ b/vendor/mdbook/src/utils/string.rs @@ -1,3 +1,4 @@ +use once_cell::sync::Lazy; use regex::Regex; use std::ops::Bound::{Excluded, Included, Unbounded}; use std::ops::RangeBounds; @@ -23,10 +24,10 @@ pub fn take_lines<R: RangeBounds<usize>>(s: &str, range: R) -> String { } } -lazy_static! { - static ref ANCHOR_START: Regex = Regex::new(r"ANCHOR:\s*(?P<anchor_name>[\w_-]+)").unwrap(); - static ref ANCHOR_END: Regex = Regex::new(r"ANCHOR_END:\s*(?P<anchor_name>[\w_-]+)").unwrap(); -} +static ANCHOR_START: Lazy<Regex> = + Lazy::new(|| Regex::new(r"ANCHOR:\s*(?P<anchor_name>[\w_-]+)").unwrap()); +static ANCHOR_END: Lazy<Regex> = + Lazy::new(|| Regex::new(r"ANCHOR_END:\s*(?P<anchor_name>[\w_-]+)").unwrap()); /// Take anchored lines from a string. /// Lines containing anchor are ignored. |