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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: utils/markdown/markdown.dart
diff --git a/utils/markdown/markdown.dart b/utils/markdown/markdown.dart
new file mode 100644
index 0000000000000000000000000000000000000000..bc61fc9afa55faf9a5af9212e5f167494b73c555
--- /dev/null
+++ b/utils/markdown/markdown.dart
@@ -0,0 +1,47 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// Standalone script for parsing markdown from files and converting to HTML.
+#library('markdown');
+
+#import('lib.dart');
+
+main() {
+ final args = (new Options()).arguments;
+
+ if (args.length > 2) {
+ print('Usage:');
+ 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!
+ print('');
+ print('Reads a file containing markdown and converts it to HTML.');
+ print('If <outputfile> is omitted, prints to stdout.');
+ return;
+ }
+
+ final source = readFile(args[0]);
+ final html = markdownToHtml(source);
+
+ if (args.length == 1) {
+ print(html);
+ } else {
+ writeFile(args[1], html);
+ }
+}
+
+String readFile(String path) {
+ final file = new File(path);
+ file.openSync();
+ final length = file.lengthSync();
+ final buffer = new List<int>(length);
+ final bytes = file.readListSync(buffer, 0, length);
+ file.closeSync();
+ return new String.fromCharCodes(buffer);
+}
+
+void writeFile(String path, String text) {
+ final file = new File(path);
+ final stream = file.openOutputStream();
+ stream.write(text.charCodes());
+ stream.close();
+}

Powered by Google App Engine
This is Rietveld 408576698