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

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

Issue 8974006: Modify the dartdoc code rendering. Syntax highlightning (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years 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 /** 5 /**
6 * To use it, from this directory, run: 6 * To use it, from this directory, run:
7 * 7 *
8 * $ ./dartdoc <path to .dart file> 8 * $ ./dartdoc <path to .dart file>
9 * 9 *
10 * This will create a "docs" directory with the docs for your libraries. To 10 * This will create a "docs" directory with the docs for your libraries. To
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 * is `true` (and [includeSource] is set), also includes the source code. 563 * is `true` (and [includeSource] is set), also includes the source code.
564 */ 564 */
565 docCode(SourceSpan span, String comment, [bool showCode = false]) { 565 docCode(SourceSpan span, String comment, [bool showCode = false]) {
566 writeln('<div class="doc">'); 566 writeln('<div class="doc">');
567 if (comment != null) { 567 if (comment != null) {
568 writeln(md.markdownToHtml(comment)); 568 writeln(md.markdownToHtml(comment));
569 } 569 }
570 570
571 if (includeSource && showCode) { 571 if (includeSource && showCode) {
572 writeln('<pre class="source">'); 572 writeln('<pre class="source">');
573 write(formatCode(span)); 573 writeln(md.escapeHtml('${unindentCode(span)}'));
Bob Nystrom 2011/12/19 23:17:34 You don't need to interpolate here.
michael.haubenwallner 2011/12/20 08:54:54 Small problem on the client side: when the code st
Bob Nystrom 2011/12/20 18:46:36 Right, sorry if I wasn't clear. Escaping is defini
574 writeln('</pre>'); 574 writeln('</pre>');
575 } 575 }
576 576
577 writeln('</div>'); 577 writeln('</div>');
578 } 578 }
579 579
580 /** Get the doc comment associated with the given type. */ 580 /** Get the doc comment associated with the given type. */
581 String getTypeComment(Type type) => _comments.find(type.span); 581 String getTypeComment(Type type) => _comments.find(type.span);
582 582
583 /** Get the doc comment associated with the given method. */ 583 /** Get the doc comment associated with the given method. */
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 if (typeArgs != null) { 692 if (typeArgs != null) {
693 final args = Strings.join(map(typeArgs, (arg) => typeName(arg)), ', '); 693 final args = Strings.join(map(typeArgs, (arg) => typeName(arg)), ', ');
694 return '${type.genericType.name}&lt;$args&gt;'; 694 return '${type.genericType.name}&lt;$args&gt;';
695 } 695 }
696 696
697 // Regular type. 697 // Regular type.
698 return type.name; 698 return type.name;
699 } 699 }
700 700
701 /** 701 /**
702 * Takes a string of Dart code and turns it into sanitized HTML. 702 * Unindents a bunch of Dart code lines
Bob Nystrom 2011/12/19 23:17:34 This needs a better comment. Just take the "Remove
michael.haubenwallner 2011/12/20 08:54:54 Done.
Bob Nystrom 2011/12/20 18:46:36 When you've made changes during a review, you have
703 */ 703 */
704 formatCode(SourceSpan span) { 704 unindentCode(SourceSpan span) {
705 // Remove leading indentation to line up with first line. 705 // Remove leading indentation to line up with first line.
706 final column = getSpanColumn(span); 706 final column = getSpanColumn(span);
707 final lines = span.text.split('\n'); 707 final lines = span.text.split('\n');
708 // TODO(rnystrom): Dirty hack. 708 // TODO(rnystrom): Dirty hack.
709 for (final i = 1; i < lines.length; i++) { 709 for (final i = 1; i < lines.length; i++) {
710 lines[i] = unindent(lines[i], column); 710 lines[i] = unindent(lines[i], column);
711 } 711 }
712 712
713 final code = Strings.join(lines, '\n'); 713 final code = Strings.join(lines, '\n');
714 return code;
715 }
716
717 /**
718 * Takes a string of Dart code and turns it into sanitized HTML.
719 */
720 formatCode(SourceSpan span) {
721 final code = unindentCode(span);
714 722
715 // Syntax highlight. 723 // Syntax highlight.
716 return classifySource(new SourceFile('', code)); 724 return classifySource(new SourceFile('', code));
717 } 725 }
718 726
719 /** 727 /**
720 * This will be called whenever a doc comment hits a `[name]` in square 728 * This will be called whenever a doc comment hits a `[name]` in square
721 * brackets. It will try to figure out what the name refers to and link or 729 * brackets. It will try to figure out what the name refers to and link or
722 * style it appropriately. 730 * style it appropriately.
723 */ 731 */
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 790
783 return new md.Element.text('code', name); 791 return new md.Element.text('code', name);
784 } 792 }
785 793
786 // TODO(rnystrom): Move into SourceSpan? 794 // TODO(rnystrom): Move into SourceSpan?
787 int getSpanColumn(SourceSpan span) { 795 int getSpanColumn(SourceSpan span) {
788 final line = span.file.getLine(span.start); 796 final line = span.file.getLine(span.start);
789 return span.file.getColumn(line, span.start); 797 return span.file.getColumn(line, span.start);
790 } 798 }
791 } 799 }
OLDNEW
« no previous file with comments | « AUTHORS ('k') | dart/utils/dartdoc/interact.dart » ('j') | dart/utils/dartdoc/interact.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698