in lib/src/highlighter.dart [190:261]
String highlight() {
_writeFileStart(_lines.first.url);
// Each index of this list represents a column after the sidebar that could
// contain a line indicating an active highlight. If it's `null`, that
// column is empty; if it contains a highlight, it should be drawn for that column.
final highlightsByColumn =
List<_Highlight?>.filled(_maxMultilineSpans, null);
for (var i = 0; i < _lines.length; i++) {
final line = _lines[i];
if (i > 0) {
final lastLine = _lines[i - 1];
if (lastLine.url != line.url) {
_writeSidebar(end: glyph.upEnd);
_buffer.writeln();
_writeFileStart(line.url);
} else if (lastLine.number + 1 != line.number) {
_writeSidebar(text: '...');
_buffer.writeln();
}
}
// If a highlight covers the entire first line other than initial
// whitespace, don't bother pointing out exactly where it begins. Iterate
// in reverse so that longer highlights (which are sorted after shorter
// highlights) appear further out, leading to fewer crossed lines.
for (var highlight in line.highlights.reversed) {
if (isMultiline(highlight.span) &&
highlight.span.start.line == line.number &&
_isOnlyWhitespace(
line.text.substring(0, highlight.span.start.column))) {
replaceFirstNull(highlightsByColumn, highlight);
}
}
_writeSidebar(line: line.number);
_buffer.write(' ');
_writeMultilineHighlights(line, highlightsByColumn);
if (highlightsByColumn.isNotEmpty) _buffer.write(' ');
final primaryIdx =
line.highlights.indexWhere((highlight) => highlight.isPrimary);
final primary = primaryIdx == -1 ? null : line.highlights[primaryIdx];
if (primary != null) {
_writeHighlightedText(
line.text,
primary.span.start.line == line.number
? primary.span.start.column
: 0,
primary.span.end.line == line.number
? primary.span.end.column
: line.text.length,
color: _primaryColor);
} else {
_writeText(line.text);
}
_buffer.writeln();
// Always write the primary span's indicator first so that it's right next
// to the highlighted text.
if (primary != null) _writeIndicator(line, primary, highlightsByColumn);
for (var highlight in line.highlights) {
if (highlight.isPrimary) continue;
_writeIndicator(line, highlight, highlightsByColumn);
}
}
_writeSidebar(end: glyph.upEnd);
return _buffer.toString();
}