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

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: Review. Add missing file (oops!). 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
« no previous file with comments | « utils/markdown/lib.dart ('k') | utils/markdown/test/markdown_tests.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/markdown/markdown.dart
diff --git a/utils/markdown/markdown.dart b/utils/markdown/markdown.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5f9e010484f0869ca3d59634ac87e9d635ef2d1f
--- /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 markdown.dart <inputfile> [<outputfile>]');
+ 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();
+}
« no previous file with comments | « utils/markdown/lib.dart ('k') | utils/markdown/test/markdown_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698