/
markdown.dart
44 lines (37 loc) · 1022 Bytes
/
markdown.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import 'dart:async';
import 'dart:io';
import 'package:markdown/markdown.dart';
Future main(List<String> args) async {
if (args.length > 1) {
print('Usage: markdown.dart [file]');
exit(1);
}
if (args.length == 1) {
var arg = args.first;
if (arg == '--help') usage();
if (arg == '--version') {
print(version);
exit(0);
}
// Read argument as a file path.
print(markdownToHtml(new File(args[0]).readAsStringSync()));
exit(0);
}
// Read from stdin.
var buffer = new StringBuffer();
var line;
while ((line = stdin.readLineSync()) != null) buffer.writeln(line);
print(markdownToHtml(buffer.toString()));
}
void usage() {
print('''Usage:
markdown [markdown file]
Convert [markdown-file] from Markdown to HTML. If no file is passed on
the commandline, then the Markdown source is read from STDIN.
markdown --version
Print the markdown package version.
markdown --help
Print this help text.
''');
exit(0);
}