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 library markdown.html_renderer; | 5 library markdown.html_renderer; |
6 | 6 |
7 import 'ast.dart'; | 7 import 'ast.dart'; |
8 import 'document.dart'; | 8 import 'document.dart'; |
9 import 'inline_parser.dart'; | 9 import 'inline_parser.dart'; |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 bool visitElementBefore(Element element) { | 54 bool visitElementBefore(Element element) { |
55 // Hackish. Separate block-level elements with newlines. | 55 // Hackish. Separate block-level elements with newlines. |
56 if (!buffer.isEmpty && _BLOCK_TAGS.firstMatch(element.tag) != null) { | 56 if (!buffer.isEmpty && _BLOCK_TAGS.firstMatch(element.tag) != null) { |
57 buffer.write('\n'); | 57 buffer.write('\n'); |
58 } | 58 } |
59 | 59 |
60 buffer.write('<${element.tag}'); | 60 buffer.write('<${element.tag}'); |
61 | 61 |
62 // Sort the keys so that we generate stable output. | 62 // Sort the keys so that we generate stable output. |
63 // TODO(rnystrom): This assumes keys returns a fresh mutable | |
64 // collection. | |
65 final attributeNames = element.attributes.keys.toList(); | 63 final attributeNames = element.attributes.keys.toList(); |
66 attributeNames.sort((a, b) => a.compareTo(b)); | 64 attributeNames.sort((a, b) => a.compareTo(b)); |
67 for (final name in attributeNames) { | 65 for (final name in attributeNames) { |
68 buffer.write(' $name="${element.attributes[name]}"'); | 66 buffer.write(' $name="${element.attributes[name]}"'); |
69 } | 67 } |
70 | 68 |
71 if (element.isEmpty) { | 69 if (element.isEmpty) { |
72 // Empty element like <hr/>. | 70 // Empty element like <hr/>. |
73 buffer.write(' />'); | 71 buffer.write(' />'); |
74 return false; | 72 return false; |
75 } else { | 73 } else { |
76 buffer.write('>'); | 74 buffer.write('>'); |
77 return true; | 75 return true; |
78 } | 76 } |
79 } | 77 } |
80 | 78 |
81 void visitElementAfter(Element element) { | 79 void visitElementAfter(Element element) { |
82 buffer.write('</${element.tag}>'); | 80 buffer.write('</${element.tag}>'); |
83 } | 81 } |
84 } | 82 } |
OLD | NEW |