continuesAfterBlank function
Whether a blank line followed by next continues the block that before
ends with, rather than separating two blocks.
It does when next is indented under a list item — a second paragraph
or a fenced code block that belongs to the item, the shape of almost every
step-by-step answer — or under a footnote definition. The owner is the
nearest earlier line indented less than next; it continues the item
exactly when the parser would nest next under it.
For the code that cuts a document into independently parsed pieces at blank lines: cutting here moved the item's code block out of the list, and parsed alone, every line of it kept the item's indentation.
Implementation
bool continuesAfterBlank(List<String> before, String next) {
final indent = indentWidth(next);
if (indent == 0) {
return false;
}
for (var k = before.length - 1; k >= 0; k--) {
final line = before[k];
if (isBlank(line)) {
continue;
}
if (indentWidth(line) >= indent) {
continue;
}
final t = line.trimLeft();
if (unorderedMarker(t) != null || orderedMarker(t) != null) {
return true;
}
return indent >= 4 && t.startsWith('[^');
}
return false;
}