update method
Parses text, reusing the blocks of the previous text when text
starts with it. Returns whether anything changed.
Implementation
bool update(String text, {required bool complete}) {
if (_started && text == _text && complete == _complete) return false;
if (!text.startsWith(_text) || (_complete && !complete)) reset();
_started = true;
_text = text;
_complete = complete;
if (_wholeDocument || _footnoteDefinition.hasMatch(text)) {
_parseWhole(text, complete);
return true;
}
var newReferences = false;
var start = _openStart;
for (final boundary in findBlockBoundaries(
text,
start,
complete: complete,
dollarMath: syntax.dollarMath,
)) {
newReferences |= _freeze(text.substring(start, boundary));
start = boundary;
}
if (complete && start < text.length) {
newReferences |= _freeze(text.substring(start));
start = text.length;
}
_openStart = start;
if (newReferences) _parseFrozenAgain();
final open = text.substring(_openStart);
if (isBlank(open)) {
_openNodes = const [];
} else {
final document = _newDocument()
..linkReferences.addAll(_document.linkReferences);
_openNodes = document.parse(
healIncompleteMarkdown(open, dollarMath: syntax.dollarMath),
);
}
return true;
}