@@ -232,14 +232,23 @@ class InlineParser {
232
232
final openerTextNodeIndex = _tree.indexOf (openerTextNode);
233
233
final closerTextNode = closer.node;
234
234
var closerTextNodeIndex = _tree.indexOf (closerTextNode);
235
- final node = opener.syntax.close (this , opener, closer,
236
- tag: matchedTag.tag,
237
- getChildren: () =>
238
- _tree.sublist (openerTextNodeIndex + 1 , closerTextNodeIndex));
235
+ final node = opener.syntax.close (
236
+ this ,
237
+ opener,
238
+ closer,
239
+ tag: matchedTag.tag,
240
+ getChildren: () => _tree.sublist (
241
+ openerTextNodeIndex + 1 ,
242
+ closerTextNodeIndex,
243
+ ),
244
+ );
239
245
// Replace all of the nodes between the opener and the closer (which
240
246
// are now the new emphasis node's children) with the emphasis node.
241
247
_tree.replaceRange (
242
- openerTextNodeIndex + 1 , closerTextNodeIndex, [node! ]);
248
+ openerTextNodeIndex + 1 ,
249
+ closerTextNodeIndex,
250
+ [node! ],
251
+ );
243
252
// Slide [closerTextNodeIndex] back accordingly.
244
253
closerTextNodeIndex = openerTextNodeIndex + 2 ;
245
254
@@ -483,8 +492,10 @@ class EscapeSyntax extends InlineSyntax {
483
492
/// Markdown benchmarking is more mature.
484
493
class InlineHtmlSyntax extends TextSyntax {
485
494
InlineHtmlSyntax ()
486
- : super (r'<[/!?]?[A-Za-z][A-Za-z0-9-]*(?:\s[^>]*)?>' ,
487
- startCharacter: $lt);
495
+ : super (
496
+ r'<[/!?]?[A-Za-z][A-Za-z0-9-]*(?:\s[^>]*)?>' ,
497
+ startCharacter: $lt,
498
+ );
488
499
}
489
500
490
501
/// Matches autolinks like `<[email protected] >` .
@@ -716,15 +727,15 @@ class SimpleDelimiter implements Delimiter {
716
727
717
728
final int endPos;
718
729
719
- SimpleDelimiter (
720
- { required this .node,
721
- required this .char,
722
- required this .length,
723
- required this .canOpen,
724
- required this .canClose,
725
- required this .syntax,
726
- required this .endPos})
727
- : isActive = true ;
730
+ SimpleDelimiter ({
731
+ required this .node,
732
+ required this .char,
733
+ required this .length,
734
+ required this .canOpen,
735
+ required this .canClose,
736
+ required this .syntax,
737
+ required this .endPos,
738
+ }) : isActive = true ;
728
739
}
729
740
730
741
/// An implementation of [Delimiter] which uses concepts of "left-flanking" and
@@ -811,11 +822,15 @@ class DelimiterRun implements Delimiter {
811
822
812
823
/// Tries to parse a delimiter run from [runStart] (inclusive) to [runEnd]
813
824
/// (exclusive).
814
- static DelimiterRun ? tryParse (InlineParser parser, int runStart, int runEnd,
815
- {required DelimiterSyntax syntax,
816
- required List <DelimiterTag > tags,
817
- required Text node,
818
- bool allowIntraWord = false }) {
825
+ static DelimiterRun ? tryParse (
826
+ InlineParser parser,
827
+ int runStart,
828
+ int runEnd, {
829
+ required DelimiterSyntax syntax,
830
+ required List <DelimiterTag > tags,
831
+ required Text node,
832
+ bool allowIntraWord = false ,
833
+ }) {
819
834
bool leftFlanking,
820
835
rightFlanking,
821
836
precededByPunctuation,
@@ -911,12 +926,13 @@ class DelimiterSyntax extends InlineSyntax {
911
926
/// is passed, this syntax parses according to the same nesting rules as
912
927
/// emphasis delimiters. If [startCharacter] is passed, it is used as a
913
928
/// pre-matching check which is faster than matching against [pattern] .
914
- DelimiterSyntax (String pattern,
915
- {this .requiresDelimiterRun = false ,
916
- int ? startCharacter,
917
- this .allowIntraWord = false ,
918
- this .tags})
919
- : super (pattern, startCharacter: startCharacter);
929
+ DelimiterSyntax (
930
+ String pattern, {
931
+ this .requiresDelimiterRun = false ,
932
+ int ? startCharacter,
933
+ this .allowIntraWord = false ,
934
+ this .tags,
935
+ }) : super (pattern, startCharacter: startCharacter);
920
936
921
937
@override
922
938
bool onMatch (InlineParser parser, Match match) {
@@ -926,22 +942,27 @@ class DelimiterSyntax extends InlineSyntax {
926
942
final text = Text (parser.source.substring (matchStart, matchEnd));
927
943
if (! requiresDelimiterRun) {
928
944
parser._pushDelimiter (SimpleDelimiter (
929
- node: text,
930
- length: runLength,
931
- char: parser.source.codeUnitAt (matchStart),
932
- canOpen: true ,
933
- canClose: false ,
934
- syntax: this ,
935
- endPos: matchEnd));
945
+ node: text,
946
+ length: runLength,
947
+ char: parser.source.codeUnitAt (matchStart),
948
+ canOpen: true ,
949
+ canClose: false ,
950
+ syntax: this ,
951
+ endPos: matchEnd,
952
+ ));
936
953
parser.addNode (text);
937
954
return true ;
938
955
}
939
956
940
- final delimiterRun = DelimiterRun .tryParse (parser, matchStart, matchEnd,
941
- syntax: this ,
942
- node: text,
943
- allowIntraWord: allowIntraWord,
944
- tags: tags ?? []);
957
+ final delimiterRun = DelimiterRun .tryParse (
958
+ parser,
959
+ matchStart,
960
+ matchEnd,
961
+ syntax: this ,
962
+ node: text,
963
+ allowIntraWord: allowIntraWord,
964
+ tags: tags ?? [],
965
+ );
945
966
if (delimiterRun != null ) {
946
967
parser._pushDelimiter (delimiterRun);
947
968
parser.addNode (text);
@@ -979,19 +1000,25 @@ class EmphasisSyntax extends DelimiterSyntax {
979
1000
980
1001
/// Parses `**strong**` and `*emphasis*` .
981
1002
EmphasisSyntax .asterisk ()
982
- : super (r'\*+' ,
983
- requiresDelimiterRun: true , allowIntraWord: true , tags: _tags);
1003
+ : super (
1004
+ r'\*+' ,
1005
+ requiresDelimiterRun: true ,
1006
+ allowIntraWord: true ,
1007
+ tags: _tags,
1008
+ );
984
1009
985
1010
static final _tags = [DelimiterTag ('em' , 1 ), DelimiterTag ('strong' , 2 )];
986
1011
}
987
1012
988
1013
/// Matches strikethrough syntax according to the GFM spec.
989
1014
class StrikethroughSyntax extends DelimiterSyntax {
990
1015
StrikethroughSyntax ()
991
- : super ('~+' ,
992
- requiresDelimiterRun: true ,
993
- allowIntraWord: true ,
994
- tags: [DelimiterTag ('del' , 2 )]);
1016
+ : super (
1017
+ '~+' ,
1018
+ requiresDelimiterRun: true ,
1019
+ allowIntraWord: true ,
1020
+ tags: [DelimiterTag ('del' , 2 )],
1021
+ );
995
1022
}
996
1023
997
1024
@Deprecated ('Use DelimiterSyntax instead' )
@@ -1006,11 +1033,11 @@ class LinkSyntax extends DelimiterSyntax {
1006
1033
1007
1034
final Resolver linkResolver;
1008
1035
1009
- LinkSyntax (
1010
- { Resolver ? linkResolver,
1011
- String pattern = r'\[' ,
1012
- int startCharacter = $lbracket})
1013
- : linkResolver = (linkResolver ?? ((String _, [String ? __]) => null )),
1036
+ LinkSyntax ({
1037
+ Resolver ? linkResolver,
1038
+ String pattern = r'\[' ,
1039
+ int startCharacter = $lbracket,
1040
+ }) : linkResolver = (linkResolver ?? ((String _, [String ? __]) => null )),
1014
1041
super (pattern, startCharacter: startCharacter);
1015
1042
1016
1043
@override
@@ -1041,8 +1068,11 @@ class LinkSyntax extends DelimiterSyntax {
1041
1068
final leftParenIndex = parser.pos;
1042
1069
final inlineLink = _parseInlineLink (parser);
1043
1070
if (inlineLink != null ) {
1044
- return _tryCreateInlineLink (parser, inlineLink,
1045
- getChildren: getChildren);
1071
+ return _tryCreateInlineLink (
1072
+ parser,
1073
+ inlineLink,
1074
+ getChildren: getChildren,
1075
+ );
1046
1076
}
1047
1077
// At this point, we've matched `[...](`, but that `(` did not pan out to
1048
1078
// be an inline link. We must now check if `[...]` is simply a shortcut
@@ -1088,12 +1118,17 @@ class LinkSyntax extends DelimiterSyntax {
1088
1118
///
1089
1119
/// [label] does not need to be normalized.
1090
1120
Node ? _resolveReferenceLink (
1091
- String label, Map <String , LinkReference > linkReferences,
1092
- {required List <Node > Function () getChildren}) {
1121
+ String label,
1122
+ Map <String , LinkReference > linkReferences, {
1123
+ required List <Node > Function () getChildren,
1124
+ }) {
1093
1125
final linkReference = linkReferences[normalizeLinkLabel (label)];
1094
1126
if (linkReference != null ) {
1095
- return _createNode (linkReference.destination, linkReference.title,
1096
- getChildren: getChildren);
1127
+ return _createNode (
1128
+ linkReference.destination,
1129
+ linkReference.title,
1130
+ getChildren: getChildren,
1131
+ );
1097
1132
} else {
1098
1133
// This link has no reference definition. But we allow users of the
1099
1134
// library to specify a custom resolver function ([linkResolver]) that
@@ -1115,8 +1150,11 @@ class LinkSyntax extends DelimiterSyntax {
1115
1150
}
1116
1151
1117
1152
/// Create the node represented by a Markdown link.
1118
- Node _createNode (String destination, String ? title,
1119
- {required List <Node > Function () getChildren}) {
1153
+ Node _createNode (
1154
+ String destination,
1155
+ String ? title, {
1156
+ required List <Node > Function () getChildren,
1157
+ }) {
1120
1158
final children = getChildren ();
1121
1159
final element = Element ('a' , children);
1122
1160
element.attributes['href' ] = escapeAttribute (destination);
@@ -1129,17 +1167,26 @@ class LinkSyntax extends DelimiterSyntax {
1129
1167
/// Tries to create a reference link node.
1130
1168
///
1131
1169
/// Returns the link if it was successfully created, `null` otherwise.
1132
- Node ? _tryCreateReferenceLink (InlineParser parser, String label,
1133
- {required List <Node > Function () getChildren}) {
1134
- return _resolveReferenceLink (label, parser.document.linkReferences,
1135
- getChildren: getChildren);
1170
+ Node ? _tryCreateReferenceLink (
1171
+ InlineParser parser,
1172
+ String label, {
1173
+ required List <Node > Function () getChildren,
1174
+ }) {
1175
+ return _resolveReferenceLink (
1176
+ label,
1177
+ parser.document.linkReferences,
1178
+ getChildren: getChildren,
1179
+ );
1136
1180
}
1137
1181
1138
1182
// Tries to create an inline link node.
1139
1183
//
1140
1184
/// Returns the link if it was successfully created, `null` otherwise.
1141
- Node _tryCreateInlineLink (InlineParser parser, InlineLink link,
1142
- {required List <Node > Function () getChildren}) {
1185
+ Node _tryCreateInlineLink (
1186
+ InlineParser parser,
1187
+ InlineLink link, {
1188
+ required List <Node > Function () getChildren,
1189
+ }) {
1143
1190
return _createNode (link.destination, link.title, getChildren: getChildren);
1144
1191
}
1145
1192
@@ -1413,13 +1460,17 @@ class LinkSyntax extends DelimiterSyntax {
1413
1460
class ImageSyntax extends LinkSyntax {
1414
1461
ImageSyntax ({Resolver ? linkResolver})
1415
1462
: super (
1416
- linkResolver: linkResolver,
1417
- pattern: r'!\[' ,
1418
- startCharacter: $exclamation);
1463
+ linkResolver: linkResolver,
1464
+ pattern: r'!\[' ,
1465
+ startCharacter: $exclamation,
1466
+ );
1419
1467
1420
1468
@override
1421
- Element _createNode (String destination, String ? title,
1422
- {required List <Node > Function () getChildren}) {
1469
+ Element _createNode (
1470
+ String destination,
1471
+ String ? title, {
1472
+ required List <Node > Function () getChildren,
1473
+ }) {
1423
1474
final element = Element .empty ('img' );
1424
1475
final children = getChildren ();
1425
1476
element.attributes['src' ] = destination;
0 commit comments