run method
Implementation
@override
Future<ProcessData> run(ProcessData data) async {
final replacements = <Replacement>[];
final matches = _mermaidBlockRegex.allMatches(data.content);
if (matches.isEmpty) return data;
for (final Match match in matches) {
final mermaidSyntax = match.group(1);
if (mermaidSyntax == null) continue;
// Process the mermaid syntax to generate an image file
final asset = await generateAndSaveMermaidImage(mermaidSyntax);
if (asset == null) continue;
final markdown = '';
// Collect replacement information
replacements.add((
start: match.start,
end: match.end,
markdown: markdown,
));
}
var content = data.content;
// Apply replacements in reverse order
for (var replacement in replacements.reversed) {
final (:start, :end, :markdown) = replacement;
content = content.replaceRange(start, end, markdown);
}
return (
content: content,
options: data.options,
config: data.config,
);
}