OLD | NEW |
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 part of markdown; |
6 | 6 |
7 String renderToHtml(List<Node> nodes) => new HtmlRenderer().render(nodes); | 7 String renderToHtml(List<Node> nodes) => new HtmlRenderer().render(nodes); |
8 | 8 |
9 /// Translates a parsed AST to HTML. | 9 /// Translates a parsed AST to HTML. |
10 class HtmlRenderer implements NodeVisitor { | 10 class HtmlRenderer implements NodeVisitor { |
(...skipping 21 matching lines...) Expand all Loading... |
32 if (!buffer.isEmpty && | 32 if (!buffer.isEmpty && |
33 _BLOCK_TAGS.firstMatch(element.tag) != null) { | 33 _BLOCK_TAGS.firstMatch(element.tag) != null) { |
34 buffer.add('\n'); | 34 buffer.add('\n'); |
35 } | 35 } |
36 | 36 |
37 buffer.add('<${element.tag}'); | 37 buffer.add('<${element.tag}'); |
38 | 38 |
39 // Sort the keys so that we generate stable output. | 39 // Sort the keys so that we generate stable output. |
40 // TODO(rnystrom): This assumes keys returns a fresh mutable | 40 // TODO(rnystrom): This assumes keys returns a fresh mutable |
41 // collection. | 41 // collection. |
42 final attributeNames = element.attributes.keys; | 42 final attributeNames = element.attributes.keys.toList(); |
43 attributeNames.sort((a, b) => a.compareTo(b)); | 43 attributeNames.sort((a, b) => a.compareTo(b)); |
44 for (final name in attributeNames) { | 44 for (final name in attributeNames) { |
45 buffer.add(' $name="${element.attributes[name]}"'); | 45 buffer.add(' $name="${element.attributes[name]}"'); |
46 } | 46 } |
47 | 47 |
48 if (element.isEmpty) { | 48 if (element.isEmpty) { |
49 // Empty element like <hr/>. | 49 // Empty element like <hr/>. |
50 buffer.add(' />'); | 50 buffer.add(' />'); |
51 return false; | 51 return false; |
52 } else { | 52 } else { |
53 buffer.add('>'); | 53 buffer.add('>'); |
54 return true; | 54 return true; |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 void visitElementAfter(Element element) { | 58 void visitElementAfter(Element element) { |
59 buffer.add('</${element.tag}>'); | 59 buffer.add('</${element.tag}>'); |
60 } | 60 } |
61 } | 61 } |
OLD | NEW |