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

Side by Side Diff: utils/dartdoc/html_renderer.dart

Issue 9147058: Hook up the dartdoc tests to test.py, test.dart, and frog/presubmit.py. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 String renderToHtml(List<Node> nodes) => new HtmlRenderer().render(nodes); 5 String renderToHtml(List<Node> nodes) => new HtmlRenderer().render(nodes);
6 6
7 /// Translates a parsed AST to HTML. 7 /// Translates a parsed AST to HTML.
8 class HtmlRenderer implements NodeVisitor { 8 class HtmlRenderer implements NodeVisitor {
9 static final _BLOCK_TAGS = const RegExp( 9 static final _BLOCK_TAGS = const RegExp(
10 'blockquote|h1|h2|h3|h4|h5|h6|hr|p|pre'); 10 'blockquote|h1|h2|h3|h4|h5|h6|hr|p|pre');
(...skipping 16 matching lines...) Expand all
27 27
28 bool visitElementBefore(Element element) { 28 bool visitElementBefore(Element element) {
29 // Hackish. Separate block-level elements with newlines. 29 // Hackish. Separate block-level elements with newlines.
30 if (!buffer.isEmpty() && 30 if (!buffer.isEmpty() &&
31 _BLOCK_TAGS.firstMatch(element.tag) != null) { 31 _BLOCK_TAGS.firstMatch(element.tag) != null) {
32 buffer.add('\n'); 32 buffer.add('\n');
33 } 33 }
34 34
35 buffer.add('<${element.tag}'); 35 buffer.add('<${element.tag}');
36 36
37 for (final name in element.attributes.getKeys()) { 37 // Sort the keys so that we generate stable output.
38 final attributeNames = new List.from(element.attributes.getKeys());
Jennifer Messerly 2012/01/11 19:15:10 Frog has an "orderValuesByKeys" method we use when
Bob Nystrom 2012/01/11 21:28:47 Dartdoc is coupled to frog but this little markdow
39 attributeNames.sort((a, b) => a.compareTo(b));
40 for (final name in attributeNames) {
38 buffer.add(' $name="${element.attributes[name]}"'); 41 buffer.add(' $name="${element.attributes[name]}"');
39 } 42 }
40 43
41 if (element.isEmpty) { 44 if (element.isEmpty) {
42 // Empty element like <hr/>. 45 // Empty element like <hr/>.
43 buffer.add(' />'); 46 buffer.add(' />');
44 return false; 47 return false;
45 } else { 48 } else {
46 buffer.add('>'); 49 buffer.add('>');
47 return true; 50 return true;
48 } 51 }
49 } 52 }
50 53
51 void visitElementAfter(Element element) { 54 void visitElementAfter(Element element) {
52 buffer.add('</${element.tag}>'); 55 buffer.add('</${element.tag}>');
53 } 56 }
54 } 57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698