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

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

Issue 9555013: Get dartdoc in the SDK and working correctly. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update copyright date. Created 8 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 String renderToHtml(List<Node> nodes) => new HtmlRenderer().render(nodes);
6
7 /// Translates a parsed AST to HTML.
8 class HtmlRenderer implements NodeVisitor {
9 static final _BLOCK_TAGS = const RegExp(
10 'blockquote|h1|h2|h3|h4|h5|h6|hr|p|pre');
11
12 StringBuffer buffer;
13
14 HtmlRenderer();
15
16 String render(List<Node> nodes) {
17 buffer = new StringBuffer();
18
19 for (final node in nodes) node.accept(this);
20
21 return buffer.toString();
22 }
23
24 void visitText(Text text) {
25 buffer.add(text.text);
26 }
27
28 bool visitElementBefore(Element element) {
29 // Hackish. Separate block-level elements with newlines.
30 if (!buffer.isEmpty() &&
31 _BLOCK_TAGS.firstMatch(element.tag) != null) {
32 buffer.add('\n');
33 }
34
35 buffer.add('<${element.tag}');
36
37 // Sort the keys so that we generate stable output.
38 // TODO(rnystrom): This assumes getKeys() returns a fresh mutable
39 // collection.
40 final attributeNames = element.attributes.getKeys();
41 attributeNames.sort((a, b) => a.compareTo(b));
42 for (final name in attributeNames) {
43 buffer.add(' $name="${element.attributes[name]}"');
44 }
45
46 if (element.isEmpty) {
47 // Empty element like <hr/>.
48 buffer.add(' />');
49 return false;
50 } else {
51 buffer.add('>');
52 return true;
53 }
54 }
55
56 void visitElementAfter(Element element) {
57 buffer.add('</${element.tag}>');
58 }
59 }
OLDNEW
« frog/presubmit.py ('K') | « utils/dartdoc/dartdoc.dart ('k') | utils/dartdoc/htmldoc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698