Skip to main content

Module regex_cache

Module regex_cache 

Source
Expand description

Cached Regex Patterns and Fast Content Checks for Markdown Linting

This module provides a centralized collection of pre-compiled, cached regex patterns for all major Markdown constructs (headings, lists, code blocks, links, images, etc.). It also includes fast-path utility functions for quickly checking if content potentially contains certain Markdown elements, allowing rules to skip expensive processing when unnecessary.

§Performance

All regexes are compiled once at startup using lazy_static, avoiding repeated compilation and improving performance across the linter. Use these shared patterns in rules instead of compiling new regexes.

§Usage

  • Use the provided statics for common Markdown patterns.
  • Use the regex_lazy! macro for ad-hoc regexes that are not predefined.
  • Use the utility functions for fast content checks before running regexes.

Macros§

regex_lazy
Macro for defining a lazily-initialized, cached regex pattern.

Structs§

RegexCache
Global regex cache for dynamic patterns

Constants§

URL_IPV6_STR
Pattern for IPv6 URLs specifically.
URL_QUICK_CHECK_STR
Quick check pattern for early exits.
URL_SIMPLE_STR
Simple URL pattern for content detection.
URL_STANDARD_STR
Pattern for standard HTTP(S)/FTP(S) URLs with full path support.
URL_WWW_STR
Pattern for www URLs without protocol.
XMPP_URI_STR
Pattern for XMPP URIs per GFM extended autolinks specification.

Statics§

ABBREVIATION
ASTERISK_EMPHASIS
ATX_HEADING_REGEX
BLOCKQUOTE_PREFIX_RE
DISPLAY_MATH_REGEX
DOUBLE_UNDERSCORE_EMPHASIS
EMAIL_PATTERN
EMOJI_SHORTCODE_REGEX
FENCED_CODE_BLOCK_END
FENCED_CODE_BLOCK_START
FOOTNOTE_REF_REGEX
HTML_COMMENT_PATTERN
HTML_ENTITY_REGEX
HTML_HEADING_PATTERN
HTML_TAG_PATTERN
HTML_TAG_QUICK_CHECK
HTML_TAG_REGEX
HUGO_SHORTCODE_REGEX
IMAGE_REF_PATTERN
IMAGE_REGEX
INLINE_IMAGE_REGEX
INLINE_LINK_FANCY_REGEX
INLINE_MATH_REGEX
LINKED_IMAGE_INLINE_INLINE
LINKED_IMAGE_INLINE_REF
LINKED_IMAGE_REF_INLINE
LINKED_IMAGE_REF_REF
LINK_REF_PATTERN
LIST_ITEM
ORDERED_LIST_MARKER_REGEX
REF_IMAGE_REGEX
REF_LINK_REGEX
SHORTCUT_REF_REGEX
UNDERSCORE_EMPHASIS
UNORDERED_LIST_MARKER_REGEX
URL_IPV6_REGEX
IPv6 URL regex - for URLs with IPv6 addresses. See URL_IPV6_STR for documentation.
URL_PATTERN
Alias for URL_SIMPLE_REGEX. Used by MD013 for line length exemption.
URL_QUICK_CHECK_REGEX
Quick check regex - fast early-exit test. See URL_QUICK_CHECK_STR for documentation.
URL_SIMPLE_REGEX
Simple URL regex - for content detection and line length exemption. See URL_SIMPLE_STR for documentation.
URL_STANDARD_REGEX
Standard URL regex - primary pattern for bare URL detection (MD034). See URL_STANDARD_STR for documentation.
URL_WWW_REGEX
WWW URL regex - for URLs starting with www. without protocol. See URL_WWW_STR for documentation.
WIKI_LINK_REGEX
XMPP_URI_REGEX
XMPP URI regex - for GFM extended autolinks. See XMPP_URI_STR for documentation.

Functions§

escape_regex
Escapes a string to be used in a regex pattern
get_cache_stats
Get cache usage statistics
get_cached_regex
Get a regex from the global cache
is_blank_in_blockquote_context
Check if a line is blank in the context of blockquotes.