marker 0.0.1 marker: ^0.0.1 copied to clipboard
A renderer (printer) for the markdown library. Saves the parsed AST basck into markdown.
marker #
Marker is a Markdown renderer (printer) for Dart. It takes a list of Node
objects produced by
the parser and renders it back to String
.
Example (from change_list.dart)
The following code displays the contents of CHANGELOG.md
with all first-level
unordered lists changed into ordered ones.
import 'dart:io';
import 'package:markdown/markdown.dart';
import 'package:marker/marker.dart';
void main() {
final changelog = File('CHANGELOG.md');
final nodes = Document()
// Parse the file content into a list of nodes
.parseLines(changelog.readAsLinesSync())
// Replace all 1st level `ul` with `ol`
.map(convertUlToOl)
// Convert back to a list
.toList();
// Render the modified nodes back to text and print
print(Renderer().render(nodes));
}
Node convertUlToOl(Node node) {
if (node is Element && node.tag == 'ul') {
return Element('ol', node.children)..attributes.addAll(node.attributes);
}
return node;
}
Custom rendering rules #
The Renderer()
constructor accepts an optional rules
argument. This way you can provide your own
rendering rules. See DefaultRules
for more details.
Known issues #
- Reference links and images are not implemented yet.
- The default rules may not process all tags properly. Please open an issue in this case.
- Some special characters (e.g.
*
or[]
) may not be escaped in the resulting text. A more intelligent escaping logic is work in progress.