@@ -11,7 +11,6 @@ import 'dart:math';
11
11
import 'package:analyzer/dart/element/element.dart' ;
12
12
import 'package:dartdoc/src/element_type.dart' ;
13
13
import 'package:dartdoc/src/model/model.dart' ;
14
- import 'package:dartdoc/src/tuple.dart' ;
15
14
import 'package:dartdoc/src/warnings.dart' ;
16
15
import 'package:markdown/markdown.dart' as md;
17
16
@@ -895,55 +894,51 @@ final RegExp allAfterLastNewline = RegExp(r'\n.*$', multiLine: true);
895
894
// https://github.com/dart-lang/dartdoc/issues/1250#issuecomment-269257942
896
895
void showWarningsForGenericsOutsideSquareBracketsBlocks (
897
896
String text, Warnable element) {
898
- var tagPositions = findFreeHangingGenericsPositions (text);
899
- if (tagPositions.isNotEmpty) {
900
- tagPositions.forEach ((int position) {
901
- var priorContext =
902
- '${text .substring (max (position - maxPriorContext , 0 ), position )}' ;
903
- var postContext =
904
- '${text .substring (position , min (position + maxPostContext , text .length ))}' ;
905
- priorContext = priorContext.replaceAll (allBeforeFirstNewline, '' );
906
- postContext = postContext.replaceAll (allAfterLastNewline, '' );
907
- var errorMessage = '$priorContext $postContext ' ;
908
- // TODO(jcollins-g): allow for more specific error location inside comments
909
- element.warn (PackageWarning .typeAsHtml, message: errorMessage);
910
- });
911
- }
897
+ findFreeHangingGenericsPositions (text).forEach ((int position) {
898
+ var priorContext =
899
+ '${text .substring (max (position - maxPriorContext , 0 ), position )}' ;
900
+ var postContext =
901
+ '${text .substring (position , min (position + maxPostContext , text .length ))}' ;
902
+ priorContext = priorContext.replaceAll (allBeforeFirstNewline, '' );
903
+ postContext = postContext.replaceAll (allAfterLastNewline, '' );
904
+ var errorMessage = '$priorContext $postContext ' ;
905
+ // TODO(jcollins-g): allow for more specific error location inside comments
906
+ element.warn (PackageWarning .typeAsHtml, message: errorMessage);
907
+ });
912
908
}
913
909
914
- List <int > findFreeHangingGenericsPositions (String string) {
910
+ Iterable <int > findFreeHangingGenericsPositions (String string) sync * {
915
911
var currentPosition = 0 ;
916
912
var squareBracketsDepth = 0 ;
917
- var results = < int > [];
918
913
while (true ) {
919
- var nextOpenBracket = string.indexOf ('[' , currentPosition);
920
- var nextCloseBracket = string.indexOf (']' , currentPosition);
921
- var nextNonHTMLTag = string.indexOf (nonHTML, currentPosition);
922
- var nextPositions = [nextOpenBracket, nextCloseBracket, nextNonHTMLTag]
914
+ final nextOpenBracket = string.indexOf ('[' , currentPosition);
915
+ final nextCloseBracket = string.indexOf (']' , currentPosition);
916
+ final nextNonHTMLTag = string.indexOf (nonHTML, currentPosition);
917
+ final nextPositions = [nextOpenBracket, nextCloseBracket, nextNonHTMLTag]
923
918
.where ((p) => p != - 1 );
924
- if (nextPositions.isNotEmpty) {
925
- final minPos = nextPositions.reduce (min);
926
- if (nextOpenBracket == minPos) {
927
- squareBracketsDepth += 1 ;
928
- } else if (nextCloseBracket == minPos) {
929
- squareBracketsDepth = max (squareBracketsDepth - 1 , 0 );
930
- } else if (nextNonHTMLTag == minPos) {
931
- if (squareBracketsDepth == 0 ) {
932
- results.add (minPos);
933
- }
934
- }
935
- currentPosition = minPos + 1 ;
936
- } else {
919
+
920
+ if (nextPositions.isEmpty) {
937
921
break ;
938
922
}
923
+
924
+ currentPosition = nextPositions.reduce (min);
925
+ if (nextOpenBracket == currentPosition) {
926
+ squareBracketsDepth += 1 ;
927
+ } else if (nextCloseBracket == currentPosition) {
928
+ squareBracketsDepth = max (squareBracketsDepth - 1 , 0 );
929
+ } else if (nextNonHTMLTag == currentPosition) {
930
+ if (squareBracketsDepth == 0 ) {
931
+ yield currentPosition;
932
+ }
933
+ }
934
+ currentPosition++ ;
939
935
}
940
- return results;
941
936
}
942
937
943
938
class MarkdownDocument extends md.Document {
944
939
factory MarkdownDocument .withElementLinkResolver (
945
940
Canonicalization element, List <ModelCommentReference > commentRefs) {
946
- md.Node linkResolver (String name, [String _]) {
941
+ md.Node /*?*/ linkResolver (String name, [String /*?*/ _]) {
947
942
if (name.isEmpty) {
948
943
return null ;
949
944
}
@@ -969,8 +964,10 @@ class MarkdownDocument extends md.Document {
969
964
linkResolver: linkResolver,
970
965
imageLinkResolver: imageLinkResolver);
971
966
972
- /// Returns a tuple of List<md.Node> and hasExtendedContent
973
- Tuple2 <List <md.Node >, bool > parseMarkdownText (
967
+ /// Parses markdown text, collecting the first [md.Node] or all of them
968
+ /// if [processFullText] is `true` . If more than one node is present,
969
+ /// then [DocumentationParseResult.hasExtendedDocs] will be set to `true` .
970
+ DocumentationParseResult parseMarkdownText (
974
971
String text, bool processFullText) {
975
972
var hasExtendedContent = false ;
976
973
var lines = LineSplitter .split (text).toList ();
@@ -985,7 +982,7 @@ class MarkdownDocument extends md.Document {
985
982
nodes.add (node);
986
983
}
987
984
_parseInlineContent (nodes);
988
- return Tuple2 (nodes, hasExtendedContent);
985
+ return DocumentationParseResult (nodes, hasExtendedContent);
989
986
}
990
987
991
988
// From package:markdown/src/document.dart
@@ -1005,12 +1002,21 @@ class MarkdownDocument extends md.Document {
1005
1002
}
1006
1003
}
1007
1004
1005
+ class DocumentationParseResult {
1006
+ static const empty = DocumentationParseResult ([], false );
1007
+
1008
+ final List <md.Node > nodes;
1009
+ final bool hasExtendedDocs;
1010
+
1011
+ const DocumentationParseResult (this .nodes, this .hasExtendedDocs);
1012
+ }
1013
+
1008
1014
class _InlineCodeSyntax extends md.InlineSyntax {
1009
1015
_InlineCodeSyntax () : super (r'\[:\s?((?:.|\n)*?)\s?:\]' );
1010
1016
1011
1017
@override
1012
1018
bool onMatch (md.InlineParser parser, Match match) {
1013
- var element = md.Element .text ('code' , htmlEscape.convert (match[1 ]));
1019
+ var element = md.Element .text ('code' , htmlEscape.convert (match[1 ] /*!*/ ));
1014
1020
parser.addNode (element);
1015
1021
return true ;
1016
1022
}
@@ -1019,7 +1025,7 @@ class _InlineCodeSyntax extends md.InlineSyntax {
1019
1025
class _AutolinkWithoutScheme extends md.AutolinkSyntax {
1020
1026
@override
1021
1027
bool onMatch (md.InlineParser parser, Match match) {
1022
- var url = match[1 ];
1028
+ var url = match[1 ] /*!*/ ;
1023
1029
var text = htmlEscape.convert (url).replaceFirst (_hideSchemes, '' );
1024
1030
var anchor = md.Element .text ('a' , text);
1025
1031
anchor.attributes['href' ] = url;
0 commit comments