plusparse/scanner library

Low-level, single-pass line helpers shared by the block parser. No regex — everything is hand-written character scanning (ported 1:1 from the Rust plusparse scanner).

Classes

DollarMathCloser
Finds the closing $ of single-dollar maths, for one text.

Functions

backtickRunAt(String text, int i) → int
Length of the backtick run starting at i.
checkboxMarker(String trimmed) → ({bool checked, String content})?
[x] / [ ] checkbox. Returns (checked, content).
codePointAt(String text, int i) → int
The code point that starts at i, or -1 at the end.
codePointBefore(String text, int i) → int
The code point that ends just before i, or -1 at the start.
codeSpanAt(String text, int i, {int? end}) → ({int close, int run})?
The code span whose opening backtick run starts at i, if it closes.
codeSpanContent(String raw) → String
The content of a code span, normalised the CommonMark way: line endings become spaces, and one space is stripped from each end when both ends have one and the content is not all spaces — which is what lets `` `a` `` hold a backtick at its edge.
fenceOpen(String trimmed) → FenceOpen?
The fence trimmed (an already left-trimmed line) opens, or null.
firstNonSpace(String line) → int
Index of the first character that is not a space or tab, or -1.
indentWidth(String line) → int
Number of leading-indent columns (space = 1, tab = 4).
isAsciiPunctuation(int unit) → bool
Whether unit is ASCII punctuation — the set a backslash can escape.
isBlank(String line) → bool
isFenceClose(String line, FenceOpen open) → bool
Whether line closes open: the same character, at least as many of them, and nothing after but whitespace.
isHeading(String trimmed) → ({String content, int level})?
ATX heading: 1–6 # followed by a space. Returns (level, content), with the optional closing sequence (## Title ##) removed.
isHr(String trimmed) → bool
Thematic break: 3+ of -, *, or _ (optionally space-separated), or ⸻.
isUnicodePunctuation(int codePoint) → bool
Unicode punctuation in CommonMark's sense: the P and S categories.
isUnicodeWhitespace(int codePoint) → bool
Unicode whitespace in CommonMark's sense: the Zs category plus tab, line feed, form feed and carriage return. -1 (outside the text) counts as whitespace, so the start and end of a run behave like a space.
openFenceAfter(Iterable<String> lines) → FenceOpen?
Whether a fence opened in lines is still open after the last line.
orderedMarker(String trimmed) → ({String content, int number})?
N. or N) ordered marker. Returns (number, content).
paragraphEnd(String text, int i) → int
Index of the end of the paragraph containing i: the next line break that is followed by a blank line, or the end of text.
radioMarker(String trimmed) → ({String content, bool selected})?
(x) / ( ) radio. Returns (selected, content).
setextUnderlineLevel(String line) → int?
The level of a setext underline — 1 for ===, 2 for --- — or null.
startsAfterIndent(String line, int unit) → bool
Whether line starts, after up to three spaces, with unit — the cheap test that lets a line-level check skip copying a line that cannot match.
startsHtmlComment(String trimmed) → bool
Whether trimmed opens an HTML comment.
stripClosingHashes(String content) → String
content without an ATX heading's optional closing sequence.
stripIndent(String line, int max) → String
Remove up to max columns of leading indentation, returning the remainder.
unorderedMarker(String trimmed) → String?
- , * , or + bullet. Returns the content after the marker.

Typedefs

FenceOpen = ({int fenceChar, String info, int length})
The opening line of a fenced code block: a run of at least three backticks or tildes.