Source
String get sourceCode {
if (_sourceCodeCache == null) {
String contents = getFileContentsFor(element);
var node = element.computeNode();
if (node != null) {
// Find the start of the line, so that we can line up all the indents.
int i = node.offset;
while (i > 0) {
i -= 1;
if (contents[i] == '\n' || contents[i] == '\r') {
i += 1;
break;
}
}
// Trim the common indent from the source snippet.
var start = node.offset - (node.offset - i);
String source = contents.substring(start, node.end);
if (config != null && config.addCrossdart) {
source = crossdartifySource(_crossdartJson, source, element, start);
} else {
source = const HtmlEscape().convert(source);
}
source = stripIndentFromSource(source);
source = stripDartdocCommentsFromSource(source);
_sourceCodeCache = source.trim();
} else {
_sourceCodeCache = '';
}
}
return _sourceCodeCache;
}