kroki 0.0.2 kroki: ^0.0.2 copied to clipboard
Class for accessing Kroki.io web service for diagram syntax to svg rendering.
Kroki.dart #
This is a simple class to package up and send requests to the Kroki.io web service.
A live editor to editing diagrams that Kroki supports can be found at niolesk.top
Features and bugs #
Please file feature requests and bugs at the issue tracker.
Example with package:markdown #
Here is an example of using the Kroki package with package:markdown to support fenced code blocks that contain diagrams.
import 'package:kroki/kroki.dart';
import 'package:markdown/markdown.dart' as markdown;
final Kroki kroki = Kroki();
class DiagramTransfomer extends markdown.CodeBlockTransformer {
@override
markdown.Node? transformCodeBlock(
String codeBlockType, String rawCodeBlock, markdown.BlockParser parser) {
final markdown.AsyncText asyncText = markdown.AsyncText(
kroki.convertDiagram(codeBlockType, rawCodeBlock), parser,
uncompletedFutureTextValue:
rawCodeBlock // fall back to showing diagram source
);
return asyncText;
}
DiagramTransfomer() :
super(handledCodeBlockTypes:KrokiDiagramEndpoints.supportedEndpoints);
}
final diagramTransformingFencedCodeBlock =
markdown.TransformableFencedCodeBlockSyntax([DiagramTransfomer()]);
main() {
final finalHtml = await markdown.markdownToHtmlWithAsyncTransforms(markdownSource,
blockSyntaxes: [diagramTransformingFencedCodeBlock],
extensionSet: markdown.ExtensionSet.gitHubWeb);
}
final String markdownSource = r'''
# Example mermaid diagram
```mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```
''';