Skip to main content

Module scan

Module scan 

Source
Expand description

Byte-level scanning helpers ported from markmend/core/src/preprocess/utils.ts and pattern.ts. All positions are byte offsets into the original string.

ASCII needles are searched with memchr: in UTF-8, ASCII bytes never occur inside multi-byte chars, so the returned offsets are always char boundaries — safe to slice with.

Functions§

append_before_trailing_whitespace
Append suffix before trailing whitespace.
count_of
memchr 版 count(ASCII needle:偏移天然边界,SIMD 加速)。
find_closed_code_block_ranges
/```[\s\S]*?```/g — all closed fenced code ranges [start, end).
find_inline_code_ranges
/[^\n]+/-style inline code ranges [start, end)` outside code blocks.
is_escaped_character
Odd number of preceding backslashes.
is_inside_unclosed_code_block
is_position_in_ranges
is_range_overlapping_ranges
Whether [start, end) overlaps any range.
is_underscore_inside_word
is_within_code_block
is_within_html_tag
Whether position is inside an unclosed HTML tag (<...>).
is_within_link_or_image_url
Whether position is inside ](...) of a link/image.
is_within_math_block
Whether position sits inside a $$ math span (or $ inline math when enabled).
is_ws
JS \s (without unicode flag): space, tab, newline, CR, FF, VT.
join_multiline_math
Fold every $$…$$ span that crosses a line break onto one line, leaving fenced code blocks alone.
js_trim
JS String.prototype.trim-ish (ASCII + unicode whitespace).
last_non_empty_line_index
Find last non-empty line index (JS findLastNonEmptyLineIndex).
last_paragraph
last_paragraph_range
Last paragraph = content after the last blank line. Returns (start_line_index, byte_offset_of_start).
mask_inline_code_markdown_markers
Mask * _ ~ inside inline code with spaces (offsets preserved).
mask_invalid_underscore_markers
Mask escaped / intraword underscore runs with spaces.
remove_math_blocks_from_text
Remove $$...$$ block math (and optionally $...$ inline math) spans.
remove_urls_from_text
Remove code blocks, HTML tags, and link/image URL bodies from text, so markdown markers inside URLs don’t get counted.
should_ignore_underscore_marker
trailing_ws_offset
Trailing whitespace run (/\s+$/), returns byte offset of the run start.