1
+ // ignore_for_file: sort_constructors_first
1
2
import 'dart:async' ;
2
3
import 'dart:io' ;
3
4
@@ -14,13 +15,13 @@ Future<Null> main() async {
14
15
"design.md"
15
16
];
16
17
List <Section > sections =
17
- filenames.map ((name) => new Section (dirPath, name)).toList ();
18
+ filenames.map ((name) => Section (dirPath, name)).toList ();
18
19
19
20
for (var section in sections) {
20
21
var lines = section.file.readAsLinesSync ();
21
22
// Ignore the YAML front matter (can lead to false H3 elements.
22
23
lines = lines.skip (1 ).skipWhile ((line) => line.trim () != '---' ).toList ();
23
- var document = new md.Document ();
24
+ var document = md.Document ();
24
25
25
26
// Commented out the following line because the parseRefLinks has
26
27
// disappeared. Unfortunately, that means I had to hand-patch the TOC
@@ -32,19 +33,19 @@ Future<Null> main() async {
32
33
var nodes = document.parseLines (lines);
33
34
for (md.Element element in nodes.where ((node) => node is md.Element )) {
34
35
if (element.tag == "h2" ) {
35
- var subsection = new Subsection (element);
36
+ var subsection = Subsection (element);
36
37
section.subsections.add (subsection);
37
38
continue ;
38
39
}
39
40
40
41
if (element.tag == "h3" ) {
41
- var rule = new Rule (element);
42
+ var rule = Rule (element);
42
43
section.subsections.last.rules.add (rule);
43
44
}
44
45
}
45
46
}
46
47
47
- var outFile = new File (path.join (dirPath, "toc.md" ));
48
+ var outFile = File (path.join (dirPath, "toc.md" ));
48
49
IOSink out;
49
50
try {
50
51
out = outFile.openWrite ();
@@ -105,12 +106,11 @@ class Section {
105
106
final Uri uri;
106
107
final File file;
107
108
final String name;
108
- List <Subsection > subsections = new List <Subsection >();
109
+ List <Subsection > subsections = List <Subsection >();
109
110
110
111
Section (String dirPath, String filename)
111
- : file = new File (path.join (dirPath, filename)),
112
- uri = Uri
113
- .parse ("/guides/language/effective-dart/" )
112
+ : file = File (path.join (dirPath, filename)),
113
+ uri = Uri .parse ("/guides/language/effective-dart/" )
114
114
.resolve (filename.split ('.' ).first),
115
115
name = "${filename [0 ].toUpperCase ()}"
116
116
"${filename .substring (1 ).split ('.' ).first }" ;
@@ -119,7 +119,7 @@ class Section {
119
119
class Subsection {
120
120
final String name;
121
121
final String fragment;
122
- List <Rule > rules = new List <Rule >();
122
+ List <Rule > rules = List <Rule >();
123
123
Subsection (md.Element element)
124
124
: name = _concatenatedText (element),
125
125
fragment = generateAnchorHash (element);
@@ -129,15 +129,15 @@ class Subsection {
129
129
String generateAnchorHash (md.Element element) => _concatenatedText (element)
130
130
.toLowerCase ()
131
131
.trim ()
132
- .replaceFirst (new RegExp (r'^[^a-z]+' ), '' )
133
- .replaceAll (new RegExp (r'[^a-z0-9 _-]' ), '' )
134
- .replaceAll (new RegExp (r'\s' ), '-' );
132
+ .replaceFirst (RegExp (r'^[^a-z]+' ), '' )
133
+ .replaceAll (RegExp (r'[^a-z0-9 _-]' ), '' )
134
+ .replaceAll (RegExp (r'\s' ), '-' );
135
135
136
136
/// Concatenates the text found in all the children of [element] .
137
137
String _concatenatedText (md.Element element) => element.children
138
138
.map ((child) =>
139
139
(child is md.Text ) ? unescape (child.text) : _concatenatedText (child))
140
140
.join ('' );
141
141
142
- final _unescape = new HtmlUnescape ();
142
+ final _unescape = HtmlUnescape ();
143
143
String unescape (String input) => _unescape.convert (input);
0 commit comments