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

Side by Side Diff: third_party/pkg/markdown/lib/src/html_renderer.dart

Issue 189333002: pkg/docgen: update markdown to 0.5.1 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updates Created 6 years, 9 months 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of markdown; 5 library markdown.html_renderer;
6
7 import 'ast.dart';
8 import 'document.dart';
9
10 /// Converts the given string of markdown to HTML.
11 String markdownToHtml(String markdown, {inlineSyntaxes, linkResolver,
12 bool inlineOnly: false}) {
13 var document = new Document(inlineSyntaxes: inlineSyntaxes,
14 linkResolver: linkResolver);
15
16 if (inlineOnly) {
17 return renderToHtml(document.parseInline(markdown));
18 } else {
19 // Replace windows line endings with unix line endings, and split.
20 var lines = markdown.replaceAll('\r\n','\n').split('\n');
21 document.parseRefLinks(lines);
22 var blocks = document.parseLines(lines);
23 return renderToHtml(blocks);
24 }
25 }
6 26
7 String renderToHtml(List<Node> nodes) => new HtmlRenderer().render(nodes); 27 String renderToHtml(List<Node> nodes) => new HtmlRenderer().render(nodes);
8 28
9 /// Translates a parsed AST to HTML. 29 /// Translates a parsed AST to HTML.
10 class HtmlRenderer implements NodeVisitor { 30 class HtmlRenderer implements NodeVisitor {
11 static final _BLOCK_TAGS = new RegExp( 31 static final _BLOCK_TAGS = new RegExp(
12 'blockquote|h1|h2|h3|h4|h5|h6|hr|p|pre'); 32 'blockquote|h1|h2|h3|h4|h5|h6|hr|p|pre');
13 33
14 StringBuffer buffer; 34 StringBuffer buffer;
15 35
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } else { 72 } else {
53 buffer.write('>'); 73 buffer.write('>');
54 return true; 74 return true;
55 } 75 }
56 } 76 }
57 77
58 void visitElementAfter(Element element) { 78 void visitElementAfter(Element element) {
59 buffer.write('</${element.tag}>'); 79 buffer.write('</${element.tag}>');
60 } 80 }
61 } 81 }
OLDNEW
« no previous file with comments | « third_party/pkg/markdown/lib/src/document.dart ('k') | third_party/pkg/markdown/lib/src/inline_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698