| OLD | NEW |
| 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 Loading... |
| 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))); |
| 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 Loading... |
| 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}<$args>'; | 694 return '${type.genericType.name}<$args>'; |
| 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 * Remove leading indentation to line up with first line. |
| 703 */ | 703 */ |
| 704 formatCode(SourceSpan span) { | 704 unindentCode(SourceSpan span) { |
| 705 // Remove leading indentation to line up with first line. | |
| 706 final column = getSpanColumn(span); | 705 final column = getSpanColumn(span); |
| 707 final lines = span.text.split('\n'); | 706 final lines = span.text.split('\n'); |
| 708 // TODO(rnystrom): Dirty hack. | 707 // TODO(rnystrom): Dirty hack. |
| 709 for (final i = 1; i < lines.length; i++) { | 708 for (final i = 1; i < lines.length; i++) { |
| 710 lines[i] = unindent(lines[i], column); | 709 lines[i] = unindent(lines[i], column); |
| 711 } | 710 } |
| 712 | 711 |
| 713 final code = Strings.join(lines, '\n'); | 712 final code = Strings.join(lines, '\n'); |
| 713 return code; |
| 714 } |
| 715 |
| 716 /** |
| 717 * Takes a string of Dart code and turns it into sanitized HTML. |
| 718 */ |
| 719 formatCode(SourceSpan span) { |
| 720 final code = unindentCode(span); |
| 714 | 721 |
| 715 // Syntax highlight. | 722 // Syntax highlight. |
| 716 return classifySource(new SourceFile('', code)); | 723 return classifySource(new SourceFile('', code)); |
| 717 } | 724 } |
| 718 | 725 |
| 719 /** | 726 /** |
| 720 * This will be called whenever a doc comment hits a `[name]` in square | 727 * 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 | 728 * brackets. It will try to figure out what the name refers to and link or |
| 722 * style it appropriately. | 729 * style it appropriately. |
| 723 */ | 730 */ |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 | 789 |
| 783 return new md.Element.text('code', name); | 790 return new md.Element.text('code', name); |
| 784 } | 791 } |
| 785 | 792 |
| 786 // TODO(rnystrom): Move into SourceSpan? | 793 // TODO(rnystrom): Move into SourceSpan? |
| 787 int getSpanColumn(SourceSpan span) { | 794 int getSpanColumn(SourceSpan span) { |
| 788 final line = span.file.getLine(span.start); | 795 final line = span.file.getLine(span.start); |
| 789 return span.file.getColumn(line, span.start); | 796 return span.file.getColumn(line, span.start); |
| 790 } | 797 } |
| 791 } | 798 } |
| OLD | NEW |