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.
ListMarker
A list item's marker, as CommonMark reads it.

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.
continuesAfterBlank(List<String> before, String next) → bool
Whether a blank line followed by next continues the block that before ends with, rather than separating two blocks.
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.
followsPrice(String text, int i) → bool
Whether the $ at i directly follows an amount (5$, 9.99$, 1,000$) that starts a word, and ends its own word.
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 or tab, or ending the line — # alone is an empty heading. Returns (level, content), with the optional closing sequence (## Title ##) removed.
isHr(String trimmed) → bool
Thematic break: 3+ of -, *, or _ (optionally space-separated), or ⸻.
isMathBody(String tex) → bool
Whether tex — the inside of \(…\) or \[…\] — is a formula.
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.
leadsPrice(String text, int i) → bool
Whether the $ at i is directly followed by an amount: digits, with , groups and a . fraction (5, 1,000, 9.99), an optional size suffix (k, K, M, B, bn, m), then the end of the word.
listMarkerAt(String line) → ListMarker?
The list marker opening line — -, + or *, or up to nine digits and . or ) — followed by whitespace or the end of the line.
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.
quoteDepth(String line) → int
How many > quote markers open line.
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.
unquoted(String line) → String
line without its leading > quote markers and indentation — what a fence check has to look at, so > ```bash is seen as the fence it is.

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.