isHeading function
ATX heading: 1–6 # followed by a space. Returns (level, content), with
the optional closing sequence (## Title ##) removed.
Implementation
({int level, String content})? isHeading(String trimmed) {
var level = 0;
while (level < trimmed.length && trimmed.codeUnitAt(level) == _hash) {
level += 1;
}
if (level >= 1 &&
level <= 6 &&
level < trimmed.length &&
trimmed.codeUnitAt(level) == _space) {
return (
level: level,
content: stripClosingHashes(trimmed.substring(level + 1).trim()),
);
}
return null;
}