OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 * Code for reading an HTML API description. | 6 * Code for reading an HTML API description. |
7 */ | 7 */ |
8 library from.html; | 8 library from.html; |
9 | 9 |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 return types; | 286 return types; |
287 } | 287 } |
288 | 288 |
289 /** | 289 /** |
290 * Read the API description from the file 'spec_input.html'. | 290 * Read the API description from the file 'spec_input.html'. |
291 */ | 291 */ |
292 Api readApi() { | 292 Api readApi() { |
293 File htmlFile = new File('spec_input.html'); | 293 File htmlFile = new File('spec_input.html'); |
294 String htmlContents = htmlFile.readAsStringSync(); | 294 String htmlContents = htmlFile.readAsStringSync(); |
295 dom.Document document = parser.parse(htmlContents); | 295 dom.Document document = parser.parse(htmlContents); |
296 return apiFromHtml(document.firstChild); | 296 dom.Element htmlElement = document.children |
| 297 .singleWhere((element) => element.localName.toLowerCase() == 'html'); |
| 298 return apiFromHtml(htmlElement); |
297 } | 299 } |
298 | 300 |
299 void recurse(dom.Element parent, String context, | 301 void recurse(dom.Element parent, String context, |
300 Map<String, ElementProcessor> elementProcessors) { | 302 Map<String, ElementProcessor> elementProcessors) { |
301 for (String key in elementProcessors.keys) { | 303 for (String key in elementProcessors.keys) { |
302 if (!specialElements.contains(key)) { | 304 if (!specialElements.contains(key)) { |
303 throw new Exception('$context: $key is not a special element'); | 305 throw new Exception('$context: $key is not a special element'); |
304 } | 306 } |
305 } | 307 } |
306 for (dom.Node node in parent.nodes) { | 308 for (dom.Node node in parent.nodes) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 TypeDefinition typeDefinition = typeDefinitionFromHtml(child); | 538 TypeDefinition typeDefinition = typeDefinitionFromHtml(child); |
537 types[typeDefinition.name] = typeDefinition; | 539 types[typeDefinition.name] = typeDefinition; |
538 } | 540 } |
539 }); | 541 }); |
540 return new Types(types, html); | 542 return new Types(types, html); |
541 } | 543 } |
542 | 544 |
543 typedef void ElementProcessor(dom.Element element); | 545 typedef void ElementProcessor(dom.Element element); |
544 | 546 |
545 typedef void TextProcessor(dom.Text text); | 547 typedef void TextProcessor(dom.Text text); |
OLD | NEW |