1use fancy_regex::Regex as FancyRegex;
23use regex::Regex;
24use std::collections::HashMap;
25use std::sync::LazyLock;
26use std::sync::{Arc, Mutex};
27
28#[derive(Debug)]
30pub struct RegexCache {
31 cache: HashMap<String, Arc<Regex>>,
32 fancy_cache: HashMap<String, Arc<FancyRegex>>,
33 usage_stats: HashMap<String, u64>,
34}
35
36impl Default for RegexCache {
37 fn default() -> Self {
38 Self::new()
39 }
40}
41
42impl RegexCache {
43 pub fn new() -> Self {
44 Self {
45 cache: HashMap::new(),
46 fancy_cache: HashMap::new(),
47 usage_stats: HashMap::new(),
48 }
49 }
50
51 pub fn get_regex(&mut self, pattern: &str) -> Result<Arc<Regex>, regex::Error> {
53 if let Some(regex) = self.cache.get(pattern) {
54 *self.usage_stats.entry(pattern.to_string()).or_insert(0) += 1;
55 return Ok(regex.clone());
56 }
57
58 let regex = Arc::new(Regex::new(pattern)?);
59 self.cache.insert(pattern.to_string(), regex.clone());
60 *self.usage_stats.entry(pattern.to_string()).or_insert(0) += 1;
61 Ok(regex)
62 }
63
64 pub fn get_fancy_regex(&mut self, pattern: &str) -> Result<Arc<FancyRegex>, Box<fancy_regex::Error>> {
66 if let Some(regex) = self.fancy_cache.get(pattern) {
67 *self.usage_stats.entry(pattern.to_string()).or_insert(0) += 1;
68 return Ok(regex.clone());
69 }
70
71 match FancyRegex::new(pattern) {
72 Ok(regex) => {
73 let arc_regex = Arc::new(regex);
74 self.fancy_cache.insert(pattern.to_string(), arc_regex.clone());
75 *self.usage_stats.entry(pattern.to_string()).or_insert(0) += 1;
76 Ok(arc_regex)
77 }
78 Err(e) => Err(Box::new(e)),
79 }
80 }
81
82 pub fn get_stats(&self) -> HashMap<String, u64> {
84 self.usage_stats.clone()
85 }
86
87 pub fn clear(&mut self) {
89 self.cache.clear();
90 self.fancy_cache.clear();
91 self.usage_stats.clear();
92 }
93}
94
95static GLOBAL_REGEX_CACHE: LazyLock<Arc<Mutex<RegexCache>>> = LazyLock::new(|| Arc::new(Mutex::new(RegexCache::new())));
97
98pub fn get_cached_regex(pattern: &str) -> Result<Arc<Regex>, regex::Error> {
104 let mut cache = GLOBAL_REGEX_CACHE.lock().unwrap_or_else(|poisoned| {
105 let mut guard = poisoned.into_inner();
107 guard.clear();
108 guard
109 });
110 cache.get_regex(pattern)
111}
112
113pub fn get_cached_fancy_regex(pattern: &str) -> Result<Arc<FancyRegex>, Box<fancy_regex::Error>> {
119 let mut cache = GLOBAL_REGEX_CACHE.lock().unwrap_or_else(|poisoned| {
120 let mut guard = poisoned.into_inner();
122 guard.clear();
123 guard
124 });
125 cache.get_fancy_regex(pattern)
126}
127
128pub fn get_cache_stats() -> HashMap<String, u64> {
132 match GLOBAL_REGEX_CACHE.lock() {
133 Ok(cache) => cache.get_stats(),
134 Err(_) => HashMap::new(),
135 }
136}
137
138#[macro_export]
156macro_rules! regex_lazy {
157 ($pattern:expr) => {{
158 static REGEX: LazyLock<regex::Regex> = LazyLock::new(|| regex::Regex::new($pattern).unwrap());
159 &*REGEX
160 }};
161}
162
163#[macro_export]
170macro_rules! regex_cached {
171 ($pattern:expr) => {{ $crate::utils::regex_cache::get_cached_regex($pattern).expect("Failed to compile regex") }};
172}
173
174#[macro_export]
181macro_rules! fancy_regex_cached {
182 ($pattern:expr) => {{ $crate::utils::regex_cache::get_cached_fancy_regex($pattern).expect("Failed to compile fancy regex") }};
183}
184
185pub use crate::regex_lazy;
187
188pub const URL_STANDARD_STR: &str = concat!(
222 r#"(?:https?|ftps?|ftp)://"#, r#"(?:"#,
224 r#"\[[0-9a-fA-F:%.\-a-zA-Z]+\]"#, r#"|"#,
226 r#"[^\s<>\[\]()\\'\"`/]+"#, r#")"#,
228 r#"(?::\d+)?"#, r#"(?:/[^\s<>\[\]\\'\"`]*)?"#, r#"(?:\?[^\s<>\[\]\\'\"`]*)?"#, r#"(?:#[^\s<>\[\]\\'\"`]*)?"#, );
233
234pub const URL_WWW_STR: &str = concat!(
247 r#"www\.(?:[a-zA-Z0-9][-a-zA-Z0-9]*\.)+[a-zA-Z]{2,}"#, r#"(?::\d+)?"#, r#"(?:/[^\s<>\[\]\\'\"`]*)?"#, r#"(?:\?[^\s<>\[\]\\'\"`]*)?"#, r#"(?:#[^\s<>\[\]\\'\"`]*)?"#, );
253
254pub const URL_IPV6_STR: &str = concat!(
259 r#"(?:https?|ftps?|ftp)://"#,
260 r#"\[[0-9a-fA-F:%.\-a-zA-Z]+\]"#, r#"(?::\d+)?"#, r#"(?:/[^\s<>\[\]\\'\"`]*)?"#, r#"(?:\?[^\s<>\[\]\\'\"`]*)?"#, r#"(?:#[^\s<>\[\]\\'\"`]*)?"#, );
266
267pub const XMPP_URI_STR: &str = r#"xmpp:[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(?:/[^\s<>\[\]\\'\"`]*)?"#;
276
277pub const URL_QUICK_CHECK_STR: &str = r#"(?:https?|ftps?|ftp|xmpp)://|xmpp:|@|www\."#;
283
284pub const URL_SIMPLE_STR: &str = r#"(?:https?|ftps?|ftp)://[^\s<>]+[^\s<>.,]"#;
290
291pub static URL_STANDARD_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(URL_STANDARD_STR).unwrap());
296
297pub static URL_WWW_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(URL_WWW_STR).unwrap());
300
301pub static URL_IPV6_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(URL_IPV6_STR).unwrap());
304
305pub static URL_QUICK_CHECK_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(URL_QUICK_CHECK_STR).unwrap());
308
309pub static URL_SIMPLE_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(URL_SIMPLE_STR).unwrap());
312
313pub static URL_PATTERN: LazyLock<Regex> = LazyLock::new(|| URL_SIMPLE_REGEX.clone());
315
316pub static XMPP_URI_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(XMPP_URI_STR).unwrap());
319
320pub static ATX_HEADING_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^(\s*)(#{1,6})(\s+|$)").unwrap());
322pub static CLOSED_ATX_HEADING_REGEX: LazyLock<Regex> =
323 LazyLock::new(|| Regex::new(r"^(\s*)(#{1,6})(\s+)(.*)(\s+)(#+)(\s*)$").unwrap());
324pub static SETEXT_HEADING_REGEX: LazyLock<Regex> =
325 LazyLock::new(|| Regex::new(r"^(\s*)[^\s]+.*\n(\s*)(=+|-+)\s*$").unwrap());
326pub static TRAILING_PUNCTUATION_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"[.,:);!?]$").unwrap());
327
328pub static ATX_HEADING_WITH_CAPTURE: LazyLock<Regex> =
330 LazyLock::new(|| Regex::new(r"^(#{1,6})\s+(.+?)(?:\s+#*\s*)?$").unwrap());
331pub static SETEXT_HEADING_WITH_CAPTURE: LazyLock<FancyRegex> =
332 LazyLock::new(|| FancyRegex::new(r"^([^\n]+)\n([=\-])\2+\s*$").unwrap());
333
334pub static UNORDERED_LIST_MARKER_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^(\s*)([*+-])(\s+)").unwrap());
336pub static ORDERED_LIST_MARKER_REGEX: LazyLock<Regex> =
337 LazyLock::new(|| Regex::new(r"^(\s*)(\d+)([.)])(\s+)").unwrap());
338pub static LIST_MARKER_ANY_REGEX: LazyLock<Regex> =
339 LazyLock::new(|| Regex::new(r"^(\s*)(?:([*+-])|(\d+)[.)])(\s+)").unwrap());
340
341pub static FENCED_CODE_BLOCK_START_REGEX: LazyLock<Regex> =
343 LazyLock::new(|| Regex::new(r"^(\s*)(```|~~~)(.*)$").unwrap());
344pub static FENCED_CODE_BLOCK_END_REGEX: LazyLock<Regex> =
345 LazyLock::new(|| Regex::new(r"^(\s*)(```|~~~)(\s*)$").unwrap());
346pub static INDENTED_CODE_BLOCK_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^(\s{4,})(.*)$").unwrap());
347pub static CODE_FENCE_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^(`{3,}|~{3,})").unwrap());
348
349pub static EMPHASIS_REGEX: LazyLock<FancyRegex> =
351 LazyLock::new(|| FancyRegex::new(r"(\s|^)(\*{1,2}|_{1,2})(?=\S)(.+?)(?<=\S)(\2)(\s|$)").unwrap());
352pub static SPACE_IN_EMPHASIS_REGEX: LazyLock<FancyRegex> =
353 LazyLock::new(|| FancyRegex::new(r"(\*|_)(\s+)(.+?)(\s+)(\1)").unwrap());
354
355pub static ASTERISK_EMPHASIS: LazyLock<Regex> =
359 LazyLock::new(|| Regex::new(r"(?:^|[^*])\*(\s+[^*]+\s*|\s*[^*]+\s+)\*(?:[^*]|$)").unwrap());
360pub static UNDERSCORE_EMPHASIS: LazyLock<Regex> =
361 LazyLock::new(|| Regex::new(r"(?:^|[^_])_(\s+[^_]+\s*|\s*[^_]+\s+)_(?:[^_]|$)").unwrap());
362pub static DOUBLE_UNDERSCORE_EMPHASIS: LazyLock<Regex> =
363 LazyLock::new(|| Regex::new(r"(?:^|[^_])__(\s+[^_]+\s*|\s*[^_]+\s+)__(?:[^_]|$)").unwrap());
364pub static DOUBLE_ASTERISK_EMPHASIS: LazyLock<FancyRegex> =
365 LazyLock::new(|| FancyRegex::new(r"\*\*\s+([^*]+?)\s+\*\*").unwrap());
366pub static DOUBLE_ASTERISK_SPACE_START: LazyLock<FancyRegex> =
367 LazyLock::new(|| FancyRegex::new(r"\*\*\s+([^*]+?)\*\*").unwrap());
368pub static DOUBLE_ASTERISK_SPACE_END: LazyLock<FancyRegex> =
369 LazyLock::new(|| FancyRegex::new(r"\*\*([^*]+?)\s+\*\*").unwrap());
370
371pub static FENCED_CODE_BLOCK_START: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^(\s*)```(?:[^`\r\n]*)$").unwrap());
373pub static FENCED_CODE_BLOCK_END: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^(\s*)```\s*$").unwrap());
374pub static ALTERNATE_FENCED_CODE_BLOCK_START: LazyLock<Regex> =
375 LazyLock::new(|| Regex::new(r"^(\s*)~~~(?:[^~\r\n]*)$").unwrap());
376pub static ALTERNATE_FENCED_CODE_BLOCK_END: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^(\s*)~~~\s*$").unwrap());
377pub static INDENTED_CODE_BLOCK_PATTERN: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^(\s{4,})").unwrap());
378
379pub static HTML_TAG_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"<([a-zA-Z][^>]*)>").unwrap());
381pub static HTML_SELF_CLOSING_TAG_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"<([a-zA-Z][^>]*/)>").unwrap());
382pub static HTML_TAG_FINDER: LazyLock<Regex> = LazyLock::new(|| Regex::new("(?i)</?[a-zA-Z][^>]*>").unwrap());
383pub static HTML_OPENING_TAG_FINDER: LazyLock<Regex> = LazyLock::new(|| Regex::new("(?i)<[a-zA-Z][^>]*>").unwrap());
384pub static HTML_TAG_QUICK_CHECK: LazyLock<Regex> = LazyLock::new(|| Regex::new("(?i)</?[a-zA-Z]").unwrap());
385
386pub static LINK_REFERENCE_DEFINITION_REGEX: LazyLock<Regex> =
388 LazyLock::new(|| Regex::new(r"^\s*\[([^\]]+)\]:\s+(.+)$").unwrap());
389pub static INLINE_LINK_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\[([^\]]+)\]\(([^)]+)\)").unwrap());
390pub static LINK_TEXT_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\[([^\]]*)\]").unwrap());
391pub static LINK_REGEX: LazyLock<FancyRegex> =
392 LazyLock::new(|| FancyRegex::new(r"(?<!\\)\[([^\]]*)\]\(([^)#]*)#([^)]+)\)").unwrap());
393pub static EXTERNAL_URL_REGEX: LazyLock<FancyRegex> =
394 LazyLock::new(|| FancyRegex::new(r"^(https?://|ftp://|www\.|[^/]+\.[a-z]{2,})").unwrap());
395
396pub static IMAGE_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"!\[([^\]]*)\]\(([^)]+)\)").unwrap());
398
399pub static TRAILING_WHITESPACE_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\s+$").unwrap());
401pub static MULTIPLE_BLANK_LINES_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\n{3,}").unwrap());
402
403pub static FRONT_MATTER_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^---\n.*?\n---\n").unwrap());
405
406pub static INLINE_CODE_REGEX: LazyLock<FancyRegex> = LazyLock::new(|| FancyRegex::new(r"`[^`]+`").unwrap());
408pub static BOLD_ASTERISK_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\*\*(.+?)\*\*").unwrap());
409pub static BOLD_UNDERSCORE_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"__(.+?)__").unwrap());
410pub static ITALIC_ASTERISK_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\*([^*]+?)\*").unwrap());
411pub static ITALIC_UNDERSCORE_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"_([^_]+?)_").unwrap());
412pub static LINK_TEXT_FULL_REGEX: LazyLock<FancyRegex> =
413 LazyLock::new(|| FancyRegex::new(r"\[([^\]]*)\]\([^)]*\)").unwrap());
414pub static STRIKETHROUGH_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"~~(.+?)~~").unwrap());
415pub static MULTIPLE_HYPHENS: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"-{2,}").unwrap());
416pub static TOC_SECTION_START: LazyLock<Regex> =
417 LazyLock::new(|| Regex::new(r"^#+\s*(?:Table of Contents|Contents|TOC)\s*$").unwrap());
418
419pub static BLOCKQUOTE_PREFIX_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^(\s*>+\s*)").unwrap());
421
422pub fn is_blank_in_blockquote_context(line: &str) -> bool {
445 if line.trim().is_empty() {
446 return true;
447 }
448 if let Some(m) = BLOCKQUOTE_PREFIX_RE.find(line) {
451 let remainder = &line[m.end()..];
452 is_blank_in_blockquote_context(remainder)
454 } else {
455 false
456 }
457}
458
459pub static IMAGE_REF_PATTERN: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^!\[.*?\]\[.*?\]$").unwrap());
461pub static LINK_REF_PATTERN: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^\[.*?\]:\s*https?://\S+$").unwrap());
462pub static URL_IN_TEXT: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"https?://\S+").unwrap());
470pub static SENTENCE_END: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"[.!?]\s+[A-Z]").unwrap());
471pub static ABBREVIATION: LazyLock<Regex> = LazyLock::new(|| {
472 Regex::new(r"\b(?:Mr|Mrs|Ms|Dr|Prof|Sr|Jr|vs|etc|i\.e|e\.g|Inc|Corp|Ltd|Co|St|Ave|Blvd|Rd|Ph\.D|M\.D|B\.A|M\.A|Ph\.D|U\.S|U\.K|U\.N|N\.Y|L\.A|D\.C)\.\s+[A-Z]").unwrap()
473});
474pub static DECIMAL_NUMBER: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\d+\.\s*\d+").unwrap());
475pub static LIST_ITEM: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^\s*\d+\.\s+").unwrap());
476pub static REFERENCE_LINK: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\[([^\]]*)\]\[([^\]]*)\]").unwrap());
477
478pub static EMAIL_PATTERN: LazyLock<Regex> =
480 LazyLock::new(|| Regex::new(r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}").unwrap());
481
482pub static REF_LINK_REGEX: LazyLock<FancyRegex> =
486 LazyLock::new(|| FancyRegex::new(r"(?<!\\)\[((?:[^\[\]\\]|\\.|\[[^\]]*\])*)\]\[([^\]]*)\]").unwrap());
487
488pub static SHORTCUT_REF_REGEX: LazyLock<FancyRegex> =
493 LazyLock::new(|| FancyRegex::new(r"(?<![\\)\]])\[((?:[^\[\]\\]|\\.|\[[^\]]*\])*)\](?!\s*[\[\(])").unwrap());
494
495pub static INLINE_LINK_FANCY_REGEX: LazyLock<FancyRegex> =
497 LazyLock::new(|| FancyRegex::new(r"(?<!\\)\[([^\]]+)\]\(([^)]+)\)").unwrap());
498
499pub static INLINE_IMAGE_FANCY_REGEX: LazyLock<FancyRegex> =
501 LazyLock::new(|| FancyRegex::new(r"!\[([^\]]*)\]\(([^)]+)\)").unwrap());
502
503pub static LINKED_IMAGE_INLINE_INLINE: LazyLock<FancyRegex> =
511 LazyLock::new(|| FancyRegex::new(r"\[!\[([^\]]*)\]\(([^)]+)\)\]\(([^)]+)\)").unwrap());
512
513pub static LINKED_IMAGE_REF_INLINE: LazyLock<FancyRegex> =
515 LazyLock::new(|| FancyRegex::new(r"\[!\[([^\]]*)\]\[([^\]]*)\]\]\(([^)]+)\)").unwrap());
516
517pub static LINKED_IMAGE_INLINE_REF: LazyLock<FancyRegex> =
519 LazyLock::new(|| FancyRegex::new(r"\[!\[([^\]]*)\]\(([^)]+)\)\]\[([^\]]*)\]").unwrap());
520
521pub static LINKED_IMAGE_REF_REF: LazyLock<FancyRegex> =
523 LazyLock::new(|| FancyRegex::new(r"\[!\[([^\]]*)\]\[([^\]]*)\]\]\[([^\]]*)\]").unwrap());
524
525pub static REF_IMAGE_REGEX: LazyLock<FancyRegex> =
527 LazyLock::new(|| FancyRegex::new(r"!\[((?:[^\[\]\\]|\\.|\[[^\]]*\])*)\]\[([^\]]*)\]").unwrap());
528
529pub static FOOTNOTE_REF_REGEX: LazyLock<FancyRegex> = LazyLock::new(|| FancyRegex::new(r"\[\^([^\]]+)\]").unwrap());
531
532pub static STRIKETHROUGH_FANCY_REGEX: LazyLock<FancyRegex> = LazyLock::new(|| FancyRegex::new(r"~~([^~]+)~~").unwrap());
534
535pub static WIKI_LINK_REGEX: LazyLock<FancyRegex> = LazyLock::new(|| FancyRegex::new(r"\[\[([^\]]+)\]\]").unwrap());
537
538pub static INLINE_MATH_REGEX: LazyLock<FancyRegex> =
540 LazyLock::new(|| FancyRegex::new(r"(?<!\$)\$(?!\$)([^\$]+)\$(?!\$)").unwrap());
541pub static DISPLAY_MATH_REGEX: LazyLock<FancyRegex> = LazyLock::new(|| FancyRegex::new(r"\$\$([^\$]+)\$\$").unwrap());
542
543pub static EMOJI_SHORTCODE_REGEX: LazyLock<FancyRegex> =
545 LazyLock::new(|| FancyRegex::new(r":([a-zA-Z0-9_+-]+):").unwrap());
546
547pub static HTML_TAG_PATTERN: LazyLock<FancyRegex> =
549 LazyLock::new(|| FancyRegex::new(r"</?[a-zA-Z][^>]*>|<[a-zA-Z][^>]*/\s*>").unwrap());
550
551pub static HTML_ENTITY_REGEX: LazyLock<FancyRegex> =
553 LazyLock::new(|| FancyRegex::new(r"&[a-zA-Z][a-zA-Z0-9]*;|&#\d+;|&#x[0-9a-fA-F]+;").unwrap());
554
555pub static HUGO_SHORTCODE_REGEX: LazyLock<FancyRegex> =
559 LazyLock::new(|| FancyRegex::new(r"\{\{[<%][\s\S]*?[%>]\}\}").unwrap());
560
561pub static HTML_COMMENT_PATTERN: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"<!--[\s\S]*?-->").unwrap());
563
564pub static HTML_HEADING_PATTERN: LazyLock<FancyRegex> =
566 LazyLock::new(|| FancyRegex::new(r"^\s*<h([1-6])(?:\s[^>]*)?>.*</h\1>\s*$").unwrap());
567
568pub static HEADING_CHECK: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(?m)^(?:\s*)#").unwrap());
570
571pub static HR_DASH: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^\-{3,}\s*$").unwrap());
573pub static HR_ASTERISK: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^\*{3,}\s*$").unwrap());
574pub static HR_UNDERSCORE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^_{3,}\s*$").unwrap());
575pub static HR_SPACED_DASH: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^(\-\s+){2,}\-\s*$").unwrap());
576pub static HR_SPACED_ASTERISK: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^(\*\s+){2,}\*\s*$").unwrap());
577pub static HR_SPACED_UNDERSCORE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^(_\s+){2,}_\s*$").unwrap());
578
579pub fn has_heading_markers(content: &str) -> bool {
582 content.contains('#')
583}
584
585pub fn has_list_markers(content: &str) -> bool {
587 content.contains('*')
588 || content.contains('-')
589 || content.contains('+')
590 || (content.contains('.') && content.contains(|c: char| c.is_ascii_digit()))
591}
592
593pub fn has_code_block_markers(content: &str) -> bool {
595 content.contains("```") || content.contains("~~~") || content.contains("\n ")
596 }
598
599pub fn has_emphasis_markers(content: &str) -> bool {
601 content.contains('*') || content.contains('_')
602}
603
604pub fn has_html_tags(content: &str) -> bool {
606 content.contains('<') && (content.contains('>') || content.contains("/>"))
607}
608
609pub fn has_link_markers(content: &str) -> bool {
611 (content.contains('[') && content.contains(']'))
612 || content.contains("http://")
613 || content.contains("https://")
614 || content.contains("ftp://")
615}
616
617pub fn has_image_markers(content: &str) -> bool {
619 content.contains("![")
620}
621
622pub fn contains_url(content: &str) -> bool {
625 if !content.contains("://") {
627 return false;
628 }
629
630 let chars: Vec<char> = content.chars().collect();
631 let mut i = 0;
632
633 while i < chars.len() {
634 if i + 2 < chars.len()
636 && ((chars[i] == 'h' && chars[i + 1] == 't' && chars[i + 2] == 't')
637 || (chars[i] == 'f' && chars[i + 1] == 't' && chars[i + 2] == 'p'))
638 {
639 let mut j = i;
641 while j + 2 < chars.len() {
642 if chars[j] == ':' && chars[j + 1] == '/' && chars[j + 2] == '/' {
643 return true;
644 }
645 j += 1;
646
647 if j > i + 10 {
649 break;
650 }
651 }
652 }
653 i += 1;
654 }
655
656 false
657}
658
659pub fn escape_regex(s: &str) -> String {
661 let mut result = String::with_capacity(s.len() * 2);
662
663 for c in s.chars() {
664 if matches!(
666 c,
667 '.' | '+' | '*' | '?' | '^' | '$' | '(' | ')' | '[' | ']' | '{' | '}' | '|' | '\\'
668 ) {
669 result.push('\\');
670 }
671 result.push(c);
672 }
673
674 result
675}
676
677#[cfg(test)]
678mod tests {
679 use super::*;
680
681 #[test]
682 fn test_regex_cache_new() {
683 let cache = RegexCache::new();
684 assert!(cache.cache.is_empty());
685 assert!(cache.fancy_cache.is_empty());
686 assert!(cache.usage_stats.is_empty());
687 }
688
689 #[test]
690 fn test_regex_cache_default() {
691 let cache = RegexCache::default();
692 assert!(cache.cache.is_empty());
693 assert!(cache.fancy_cache.is_empty());
694 assert!(cache.usage_stats.is_empty());
695 }
696
697 #[test]
698 fn test_get_regex_compilation() {
699 let mut cache = RegexCache::new();
700
701 let regex1 = cache.get_regex(r"\d+").unwrap();
703 assert_eq!(cache.cache.len(), 1);
704 assert_eq!(cache.usage_stats.get(r"\d+"), Some(&1));
705
706 let regex2 = cache.get_regex(r"\d+").unwrap();
708 assert_eq!(cache.cache.len(), 1);
709 assert_eq!(cache.usage_stats.get(r"\d+"), Some(&2));
710
711 assert!(Arc::ptr_eq(®ex1, ®ex2));
713 }
714
715 #[test]
716 fn test_get_regex_invalid_pattern() {
717 let mut cache = RegexCache::new();
718 let result = cache.get_regex(r"[unterminated");
719 assert!(result.is_err());
720 assert!(cache.cache.is_empty());
721 }
722
723 #[test]
724 fn test_get_fancy_regex_compilation() {
725 let mut cache = RegexCache::new();
726
727 let regex1 = cache.get_fancy_regex(r"(?<=foo)bar").unwrap();
729 assert_eq!(cache.fancy_cache.len(), 1);
730 assert_eq!(cache.usage_stats.get(r"(?<=foo)bar"), Some(&1));
731
732 let regex2 = cache.get_fancy_regex(r"(?<=foo)bar").unwrap();
734 assert_eq!(cache.fancy_cache.len(), 1);
735 assert_eq!(cache.usage_stats.get(r"(?<=foo)bar"), Some(&2));
736
737 assert!(Arc::ptr_eq(®ex1, ®ex2));
739 }
740
741 #[test]
742 fn test_get_fancy_regex_invalid_pattern() {
743 let mut cache = RegexCache::new();
744 let result = cache.get_fancy_regex(r"(?<=invalid");
745 assert!(result.is_err());
746 assert!(cache.fancy_cache.is_empty());
747 }
748
749 #[test]
750 fn test_get_stats() {
751 let mut cache = RegexCache::new();
752
753 let _ = cache.get_regex(r"\d+").unwrap();
755 let _ = cache.get_regex(r"\d+").unwrap();
756 let _ = cache.get_regex(r"\w+").unwrap();
757 let _ = cache.get_fancy_regex(r"(?<=foo)bar").unwrap();
758
759 let stats = cache.get_stats();
760 assert_eq!(stats.get(r"\d+"), Some(&2));
761 assert_eq!(stats.get(r"\w+"), Some(&1));
762 assert_eq!(stats.get(r"(?<=foo)bar"), Some(&1));
763 }
764
765 #[test]
766 fn test_clear_cache() {
767 let mut cache = RegexCache::new();
768
769 let _ = cache.get_regex(r"\d+").unwrap();
771 let _ = cache.get_fancy_regex(r"(?<=foo)bar").unwrap();
772
773 assert!(!cache.cache.is_empty());
774 assert!(!cache.fancy_cache.is_empty());
775 assert!(!cache.usage_stats.is_empty());
776
777 cache.clear();
779
780 assert!(cache.cache.is_empty());
781 assert!(cache.fancy_cache.is_empty());
782 assert!(cache.usage_stats.is_empty());
783 }
784
785 #[test]
786 fn test_global_cache_functions() {
787 let regex1 = get_cached_regex(r"\d{3}").unwrap();
789 let regex2 = get_cached_regex(r"\d{3}").unwrap();
790 assert!(Arc::ptr_eq(®ex1, ®ex2));
791
792 let fancy1 = get_cached_fancy_regex(r"(?<=test)ing").unwrap();
794 let fancy2 = get_cached_fancy_regex(r"(?<=test)ing").unwrap();
795 assert!(Arc::ptr_eq(&fancy1, &fancy2));
796
797 let stats = get_cache_stats();
799 assert!(stats.contains_key(r"\d{3}"));
800 assert!(stats.contains_key(r"(?<=test)ing"));
801 }
802
803 #[test]
804 fn test_regex_lazy_macro() {
805 let re = regex_lazy!(r"^test.*end$");
806 assert!(re.is_match("test something end"));
807 assert!(!re.is_match("test something"));
808
809 let re2 = regex_lazy!(r"^start.*finish$");
813 assert!(re2.is_match("start and finish"));
814 assert!(!re2.is_match("start without end"));
815 }
816
817 #[test]
818 fn test_has_heading_markers() {
819 assert!(has_heading_markers("# Heading"));
820 assert!(has_heading_markers("Text with # symbol"));
821 assert!(!has_heading_markers("Text without heading marker"));
822 }
823
824 #[test]
825 fn test_has_list_markers() {
826 assert!(has_list_markers("* Item"));
827 assert!(has_list_markers("- Item"));
828 assert!(has_list_markers("+ Item"));
829 assert!(has_list_markers("1. Item"));
830 assert!(!has_list_markers("Text without list markers"));
831 }
832
833 #[test]
834 fn test_has_code_block_markers() {
835 assert!(has_code_block_markers("```code```"));
836 assert!(has_code_block_markers("~~~code~~~"));
837 assert!(has_code_block_markers("Text\n indented code"));
838 assert!(!has_code_block_markers("Text without code blocks"));
839 }
840
841 #[test]
842 fn test_has_emphasis_markers() {
843 assert!(has_emphasis_markers("*emphasis*"));
844 assert!(has_emphasis_markers("_emphasis_"));
845 assert!(has_emphasis_markers("**bold**"));
846 assert!(has_emphasis_markers("__bold__"));
847 assert!(!has_emphasis_markers("no emphasis"));
848 }
849
850 #[test]
851 fn test_has_html_tags() {
852 assert!(has_html_tags("<div>content</div>"));
853 assert!(has_html_tags("<br/>"));
854 assert!(has_html_tags("<img src='test.jpg'>"));
855 assert!(!has_html_tags("no html tags"));
856 assert!(!has_html_tags("less than < but no tag"));
857 }
858
859 #[test]
860 fn test_has_link_markers() {
861 assert!(has_link_markers("[text](url)"));
862 assert!(has_link_markers("[reference][1]"));
863 assert!(has_link_markers("http://example.com"));
864 assert!(has_link_markers("https://example.com"));
865 assert!(has_link_markers("ftp://example.com"));
866 assert!(!has_link_markers("no links here"));
867 }
868
869 #[test]
870 fn test_has_image_markers() {
871 assert!(has_image_markers(""));
872 assert!(has_image_markers(""));
873 assert!(!has_image_markers("[link](url)"));
874 assert!(!has_image_markers("no images"));
875 }
876
877 #[test]
878 fn test_contains_url() {
879 assert!(contains_url("http://example.com"));
880 assert!(contains_url("Text with https://example.com link"));
881 assert!(contains_url("ftp://example.com"));
882 assert!(!contains_url("Text without URL"));
883 assert!(!contains_url("http not followed by ://"));
884
885 assert!(!contains_url("http"));
887 assert!(!contains_url("https"));
888 assert!(!contains_url("://"));
889 assert!(contains_url("Visit http://site.com now"));
890 assert!(contains_url("See https://secure.site.com/path"));
891 }
892
893 #[test]
894 fn test_contains_url_performance() {
895 let long_text = "a".repeat(10000);
897 assert!(!contains_url(&long_text));
898
899 let text_with_url = format!("{long_text}https://example.com");
901 assert!(contains_url(&text_with_url));
902 }
903
904 #[test]
905 fn test_escape_regex() {
906 assert_eq!(escape_regex("a.b"), "a\\.b");
907 assert_eq!(escape_regex("a+b*c"), "a\\+b\\*c");
908 assert_eq!(escape_regex("(test)"), "\\(test\\)");
909 assert_eq!(escape_regex("[a-z]"), "\\[a-z\\]");
910 assert_eq!(escape_regex("normal text"), "normal text");
911
912 assert_eq!(escape_regex(".$^{[(|)*+?\\"), "\\.\\$\\^\\{\\[\\(\\|\\)\\*\\+\\?\\\\");
914
915 assert_eq!(escape_regex(""), "");
917
918 assert_eq!(escape_regex("test.com/path?query=1"), "test\\.com/path\\?query=1");
920 }
921
922 #[test]
923 fn test_static_regex_patterns() {
924 assert!(URL_SIMPLE_REGEX.is_match("https://example.com"));
926 assert!(URL_SIMPLE_REGEX.is_match("http://test.org/path"));
927 assert!(URL_SIMPLE_REGEX.is_match("ftp://files.com"));
928 assert!(!URL_SIMPLE_REGEX.is_match("not a url"));
929
930 assert!(ATX_HEADING_REGEX.is_match("# Heading"));
932 assert!(ATX_HEADING_REGEX.is_match(" ## Indented"));
933 assert!(ATX_HEADING_REGEX.is_match("### "));
934 assert!(!ATX_HEADING_REGEX.is_match("Not a heading"));
935
936 assert!(UNORDERED_LIST_MARKER_REGEX.is_match("* Item"));
938 assert!(UNORDERED_LIST_MARKER_REGEX.is_match("- Item"));
939 assert!(UNORDERED_LIST_MARKER_REGEX.is_match("+ Item"));
940 assert!(ORDERED_LIST_MARKER_REGEX.is_match("1. Item"));
941 assert!(ORDERED_LIST_MARKER_REGEX.is_match("99. Item"));
942
943 assert!(FENCED_CODE_BLOCK_START_REGEX.is_match("```"));
945 assert!(FENCED_CODE_BLOCK_START_REGEX.is_match("```rust"));
946 assert!(FENCED_CODE_BLOCK_START_REGEX.is_match("~~~"));
947 assert!(FENCED_CODE_BLOCK_END_REGEX.is_match("```"));
948 assert!(FENCED_CODE_BLOCK_END_REGEX.is_match("~~~"));
949
950 assert!(BOLD_ASTERISK_REGEX.is_match("**bold**"));
952 assert!(BOLD_UNDERSCORE_REGEX.is_match("__bold__"));
953 assert!(ITALIC_ASTERISK_REGEX.is_match("*italic*"));
954 assert!(ITALIC_UNDERSCORE_REGEX.is_match("_italic_"));
955
956 assert!(HTML_TAG_REGEX.is_match("<div>"));
958 assert!(HTML_TAG_REGEX.is_match("<span class='test'>"));
959 assert!(HTML_SELF_CLOSING_TAG_REGEX.is_match("<br/>"));
960 assert!(HTML_SELF_CLOSING_TAG_REGEX.is_match("<img src='test'/>"));
961
962 assert!(TRAILING_WHITESPACE_REGEX.is_match("line with spaces "));
964 assert!(TRAILING_WHITESPACE_REGEX.is_match("tabs\t\t"));
965 assert!(MULTIPLE_BLANK_LINES_REGEX.is_match("\n\n\n"));
966 assert!(MULTIPLE_BLANK_LINES_REGEX.is_match("\n\n\n\n"));
967
968 assert!(BLOCKQUOTE_PREFIX_RE.is_match("> Quote"));
970 assert!(BLOCKQUOTE_PREFIX_RE.is_match(" > Indented quote"));
971 assert!(BLOCKQUOTE_PREFIX_RE.is_match(">> Nested"));
972 }
973
974 #[test]
975 fn test_thread_safety() {
976 use std::thread;
977
978 let handles: Vec<_> = (0..10)
979 .map(|i| {
980 thread::spawn(move || {
981 let pattern = format!(r"\d{{{i}}}");
982 let regex = get_cached_regex(&pattern).unwrap();
983 assert!(regex.is_match(&"1".repeat(i)));
984 })
985 })
986 .collect();
987
988 for handle in handles {
989 handle.join().unwrap();
990 }
991 }
992
993 #[test]
998 fn test_url_standard_basic() {
999 assert!(URL_STANDARD_REGEX.is_match("https://example.com"));
1001 assert!(URL_STANDARD_REGEX.is_match("http://example.com"));
1002 assert!(URL_STANDARD_REGEX.is_match("https://example.com/"));
1003 assert!(URL_STANDARD_REGEX.is_match("https://example.com/path"));
1004 assert!(URL_STANDARD_REGEX.is_match("ftp://files.example.com"));
1005 assert!(URL_STANDARD_REGEX.is_match("ftps://secure.example.com"));
1006
1007 assert!(!URL_STANDARD_REGEX.is_match("not a url"));
1009 assert!(!URL_STANDARD_REGEX.is_match("example.com"));
1010 assert!(!URL_STANDARD_REGEX.is_match("www.example.com"));
1011 }
1012
1013 #[test]
1014 fn test_url_standard_with_path() {
1015 assert!(URL_STANDARD_REGEX.is_match("https://example.com/path/to/page"));
1016 assert!(URL_STANDARD_REGEX.is_match("https://example.com/path/to/page.html"));
1017 assert!(URL_STANDARD_REGEX.is_match("https://example.com/path/to/page/"));
1018 }
1019
1020 #[test]
1021 fn test_url_standard_with_query() {
1022 assert!(URL_STANDARD_REGEX.is_match("https://example.com?query=value"));
1023 assert!(URL_STANDARD_REGEX.is_match("https://example.com/path?query=value"));
1024 assert!(URL_STANDARD_REGEX.is_match("https://example.com/path?a=1&b=2"));
1025 }
1026
1027 #[test]
1028 fn test_url_standard_with_fragment() {
1029 assert!(URL_STANDARD_REGEX.is_match("https://example.com#section"));
1030 assert!(URL_STANDARD_REGEX.is_match("https://example.com/path#section"));
1031 assert!(URL_STANDARD_REGEX.is_match("https://example.com/path?query=value#section"));
1032 }
1033
1034 #[test]
1035 fn test_url_standard_with_port() {
1036 assert!(URL_STANDARD_REGEX.is_match("https://example.com:8080"));
1037 assert!(URL_STANDARD_REGEX.is_match("https://example.com:443/path"));
1038 assert!(URL_STANDARD_REGEX.is_match("http://localhost:3000"));
1039 assert!(URL_STANDARD_REGEX.is_match("https://192.168.1.1:8080/path"));
1040 }
1041
1042 #[test]
1043 fn test_url_standard_wikipedia_style_parentheses() {
1044 let url = "https://en.wikipedia.org/wiki/Rust_(programming_language)";
1046 assert!(URL_STANDARD_REGEX.is_match(url));
1047
1048 let cap = URL_STANDARD_REGEX.find(url).unwrap();
1050 assert_eq!(cap.as_str(), url);
1051
1052 let url2 = "https://example.com/path_(foo)_(bar)";
1054 let cap2 = URL_STANDARD_REGEX.find(url2).unwrap();
1055 assert_eq!(cap2.as_str(), url2);
1056 }
1057
1058 #[test]
1059 fn test_url_standard_ipv6() {
1060 assert!(URL_STANDARD_REGEX.is_match("https://[::1]/path"));
1062 assert!(URL_STANDARD_REGEX.is_match("https://[2001:db8::1]:8080/path"));
1063 assert!(URL_STANDARD_REGEX.is_match("http://[fe80::1%eth0]/"));
1064 }
1065
1066 #[test]
1067 fn test_url_www_basic() {
1068 assert!(URL_WWW_REGEX.is_match("www.example.com"));
1070 assert!(URL_WWW_REGEX.is_match("www.example.co.uk"));
1071 assert!(URL_WWW_REGEX.is_match("www.sub.example.com"));
1072
1073 assert!(!URL_WWW_REGEX.is_match("example.com"));
1075
1076 assert!(URL_WWW_REGEX.is_match("https://www.example.com"));
1080 }
1081
1082 #[test]
1083 fn test_url_www_with_path() {
1084 assert!(URL_WWW_REGEX.is_match("www.example.com/path"));
1085 assert!(URL_WWW_REGEX.is_match("www.example.com/path/to/page"));
1086 assert!(URL_WWW_REGEX.is_match("www.example.com/path_(with_parens)"));
1087 }
1088
1089 #[test]
1090 fn test_url_ipv6_basic() {
1091 assert!(URL_IPV6_REGEX.is_match("https://[::1]/"));
1093 assert!(URL_IPV6_REGEX.is_match("http://[2001:db8::1]/path"));
1094 assert!(URL_IPV6_REGEX.is_match("https://[fe80::1]:8080/path"));
1095 assert!(URL_IPV6_REGEX.is_match("ftp://[::ffff:192.168.1.1]/file"));
1096 }
1097
1098 #[test]
1099 fn test_url_ipv6_with_zone_id() {
1100 assert!(URL_IPV6_REGEX.is_match("https://[fe80::1%eth0]/path"));
1102 assert!(URL_IPV6_REGEX.is_match("http://[fe80::1%25eth0]:8080/"));
1103 }
1104
1105 #[test]
1106 fn test_url_simple_detection() {
1107 assert!(URL_SIMPLE_REGEX.is_match("https://example.com"));
1109 assert!(URL_SIMPLE_REGEX.is_match("http://test.org/path"));
1110 assert!(URL_SIMPLE_REGEX.is_match("ftp://files.com/file.zip"));
1111 assert!(!URL_SIMPLE_REGEX.is_match("not a url"));
1112 }
1113
1114 #[test]
1115 fn test_url_quick_check() {
1116 assert!(URL_QUICK_CHECK_REGEX.is_match("https://example.com"));
1118 assert!(URL_QUICK_CHECK_REGEX.is_match("http://example.com"));
1119 assert!(URL_QUICK_CHECK_REGEX.is_match("ftp://files.com"));
1120 assert!(URL_QUICK_CHECK_REGEX.is_match("www.example.com"));
1121 assert!(URL_QUICK_CHECK_REGEX.is_match("user@example.com"));
1122 assert!(!URL_QUICK_CHECK_REGEX.is_match("just plain text"));
1123 }
1124
1125 #[test]
1126 fn test_url_edge_cases() {
1127 let url = "https://example.com/path";
1129 assert!(URL_STANDARD_REGEX.is_match(url));
1130
1131 let text = "Check https://example.com, it's great!";
1134 let cap = URL_STANDARD_REGEX.find(text).unwrap();
1135 assert!(cap.as_str().ends_with(','));
1137
1138 let text2 = "See <https://example.com> for more";
1140 assert!(URL_STANDARD_REGEX.is_match(text2));
1141
1142 let cap2 = URL_STANDARD_REGEX.find(text2).unwrap();
1144 assert!(!cap2.as_str().contains('>'));
1145 }
1146
1147 #[test]
1148 fn test_url_with_complex_paths() {
1149 let urls = [
1151 "https://github.com/owner/repo/blob/main/src/file.rs#L123",
1152 "https://docs.example.com/api/v2/endpoint?format=json&page=1",
1153 "https://cdn.example.com/assets/images/logo.png?v=2023",
1154 "https://search.example.com/results?q=test+query&filter=all",
1155 ];
1156
1157 for url in urls {
1158 assert!(URL_STANDARD_REGEX.is_match(url), "Should match: {url}");
1159 }
1160 }
1161
1162 #[test]
1163 fn test_url_pattern_strings_are_valid() {
1164 assert!(URL_STANDARD_REGEX.is_match("https://example.com"));
1166 assert!(URL_WWW_REGEX.is_match("www.example.com"));
1167 assert!(URL_IPV6_REGEX.is_match("https://[::1]/"));
1168 assert!(URL_QUICK_CHECK_REGEX.is_match("https://example.com"));
1169 assert!(URL_SIMPLE_REGEX.is_match("https://example.com"));
1170 }
1171
1172 #[test]
1179 fn test_is_blank_in_blockquote_context_regular_blanks() {
1180 assert!(is_blank_in_blockquote_context(""));
1182 assert!(is_blank_in_blockquote_context(" "));
1183 assert!(is_blank_in_blockquote_context("\t"));
1184 assert!(is_blank_in_blockquote_context(" \t "));
1185 }
1186
1187 #[test]
1188 fn test_is_blank_in_blockquote_context_blockquote_blanks() {
1189 assert!(is_blank_in_blockquote_context(">"));
1191 assert!(is_blank_in_blockquote_context("> "));
1192 assert!(is_blank_in_blockquote_context("> "));
1193 assert!(is_blank_in_blockquote_context(">>"));
1194 assert!(is_blank_in_blockquote_context(">> "));
1195 assert!(is_blank_in_blockquote_context(">>>"));
1196 assert!(is_blank_in_blockquote_context(">>> "));
1197 }
1198
1199 #[test]
1200 fn test_is_blank_in_blockquote_context_spaced_nested() {
1201 assert!(is_blank_in_blockquote_context("> > "));
1203 assert!(is_blank_in_blockquote_context("> > > "));
1204 assert!(is_blank_in_blockquote_context("> > "));
1205 }
1206
1207 #[test]
1208 fn test_is_blank_in_blockquote_context_with_leading_space() {
1209 assert!(is_blank_in_blockquote_context(" >"));
1211 assert!(is_blank_in_blockquote_context(" > "));
1212 assert!(is_blank_in_blockquote_context(" >>"));
1213 }
1214
1215 #[test]
1216 fn test_is_blank_in_blockquote_context_not_blank() {
1217 assert!(!is_blank_in_blockquote_context("text"));
1219 assert!(!is_blank_in_blockquote_context("> text"));
1220 assert!(!is_blank_in_blockquote_context(">> text"));
1221 assert!(!is_blank_in_blockquote_context("> | table |"));
1222 assert!(!is_blank_in_blockquote_context("| table |"));
1223 assert!(!is_blank_in_blockquote_context("> # Heading"));
1224 assert!(!is_blank_in_blockquote_context(">text")); }
1226
1227 #[test]
1228 fn test_is_blank_in_blockquote_context_edge_cases() {
1229 assert!(!is_blank_in_blockquote_context(">a")); assert!(!is_blank_in_blockquote_context("> a")); assert!(is_blank_in_blockquote_context("> ")); assert!(!is_blank_in_blockquote_context("> text")); }
1235}