applyTocMacro function
Implementation
String applyTocMacro(File file, String content) {
var lines = LineSplitter.split(content).toList();
var result = Lines();
lines = removeGeneratedBlocks(lines, 'toc');
var toc = _extractTableOfContents(lines);
lines.read((line, skip) {
result.add(line);
if (!skip && line.isMacro("toc")) {
result.add('## Table of Contents');
for (var toplevel in toc.subsections) {
result.add('');
result.add('[**${toplevel.title}**](${toplevel.link})');
for (var sublevel in toplevel.subsections) {
result.add(' - [${sublevel.title}](${sublevel.link})');
}
}
result.add(_endComment);
}
});
return result.data().join('\n');
}