Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: utils/markdown/markdown.dart

Issue 8680025: First pass at a markdown parser in Dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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');
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_bin markdown.dart <inputfile> [<outputfile>]');
Jennifer Messerly 2011/11/23 22:25:41 I think this is just "dart" now (dart_bin is going
Bob Nystrom 2011/11/29 02:56:29 Oh yeah. Fixed!
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);
34 file.openSync();
35 final length = file.lengthSync();
36 final buffer = new List<int>(length);
37 final bytes = file.readListSync(buffer, 0, length);
38 file.closeSync();
39 return new String.fromCharCodes(buffer);
40 }
41
42 void writeFile(String path, String text) {
43 final file = new File(path);
44 final stream = file.openOutputStream();
45 stream.write(text.charCodes());
46 stream.close();
47 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698