OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 /// Standalone script for parsing markdown from files and converting to HTML. | |
6 #library('markdown_app'); | |
7 | |
8 #import('lib.dart'); | |
9 | |
10 main() { | |
11 final args = (new Options()).arguments; | |
12 | |
13 if (args.length > 2) { | |
14 print('Usage:'); | |
15 print(' dart markdown.dart <inputfile> [<outputfile>]'); | |
16 print(''); | |
17 print('Reads a file containing markdown and converts it to HTML.'); | |
18 print('If <outputfile> is omitted, prints to stdout.'); | |
19 return; | |
20 } | |
21 | |
22 final source = readFile(args[0]); | |
23 final html = markdownToHtml(source); | |
24 | |
25 if (args.length == 1) { | |
26 print(html); | |
27 } else { | |
28 writeFile(args[1], html); | |
29 } | |
30 } | |
31 | |
32 String readFile(String path) { | |
33 final file = (new File(path)).openSync(); | |
34 final length = file.lengthSync(); | |
35 final buffer = new List<int>(length); | |
36 final bytes = file.readListSync(buffer, 0, length); | |
37 file.closeSync(); | |
38 return new String.fromCharCodes(buffer); | |
39 } | |
40 | |
41 void writeFile(String path, String text) { | |
42 final file = new File(path); | |
43 final stream = file.openOutputStream(); | |
44 stream.write(text.charCodes()); | |
45 stream.close(); | |
46 } | |
OLD | NEW |