Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: utils/apidoc/mdn/extract.dart

Issue 9315026: Cleanup mdn scripts (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review comment fixes Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #import ("dart:html"); 1 #import ("dart:html");
2 #import ("dart:htmlimpl"); 2 #import ("dart:htmlimpl");
3 #import ("dart:dom", prefix:"dom"); 3 #import ("dart:dom", prefix:"dom");
4 #import ("dart:json"); 4 #import ("dart:json");
5 5
6 // Workaround for HTML lib missing feature. 6 // Workaround for HTML lib missing feature.
7 Range newRange() { 7 Range newRange() {
8 return LevelDom.wrapRange(dom.document.createRange()); 8 return LevelDom.wrapRange(dom.document.createRange());
9 } 9 }
10 10
11 // Temporary range object to optimize performance computing client rects 11 // Temporary range object to optimize performance computing client rects
12 // from text nodes. 12 // from text nodes.
13 Range _tempRange; 13 Range _tempRange;
14 // Hacks because ASYNC measurement is annoying when just writing a script. 14 // Hacks because ASYNC measurement is annoying when just writing a script.
15 ClientRect getClientRect(Node n) { 15 ClientRect getClientRect(Node n) {
16 if (n is Element) { 16 if (n is Element) {
17 Element e = n; 17 dom.Element raw = unwrapDomObject(n.dynamic);
18 dom.Element raw = unwrapDomObject(e.dynamic);
19 return LevelDom.wrapClientRect(raw.getBoundingClientRect()); 18 return LevelDom.wrapClientRect(raw.getBoundingClientRect());
20 } else { 19 } else {
21 // Crazy hacks that works for nodes.... create a range and measure it. 20 // Crazy hacks that works for nodes.... create a range and measure it.
22 if (_tempRange == null) { 21 if (_tempRange == null) {
23 _tempRange = newRange(); 22 _tempRange = newRange();
24 } 23 }
25 _tempRange.setStartBefore(n); 24 _tempRange.setStartBefore(n);
26 _tempRange.setEndAfter(n); 25 _tempRange.setEndAfter(n);
27 return _tempRange.getBoundingClientRect(); 26 return _tempRange.getBoundingClientRect();
28 } 27 }
29 } 28 }
30 29
31 final DART_REMOVED = "dart_removed"; 30 /**
31 * CSS class that is added to elements in the DOM to indicate that they should
32 * be removed when extracting blocks of documentation. This is helpful when
33 * running this script in a web browser as it is easy to visually see what
34 * blocks of information were extracted when using CSS such as DEBUG_CSS
35 * which highlights elements that should be removed.
36 */
37 final DART_REMOVED = "dart-removed";
32 38
33 final DEBUG_CSS = """ 39 final DEBUG_CSS = """
34 <style type="text/css"> 40 <style type="text/css">
35 .dart_removed { 41 .dart-removed {
36 background-color: rgba(255, 0, 0, 0.5); 42 background-color: rgba(255, 0, 0, 0.5);
37 } 43 }
38 </style>"""; 44 </style>""";
39 45
40 final MIN_PIXELS_DIFFERENT_LINES = 10; 46 final MIN_PIXELS_DIFFERENT_LINES = 10;
41 47
42 final IDL_SELECTOR = "pre.eval, pre.idl"; 48 final IDL_SELECTOR = "pre.eval, pre.idl";
43 49
44 Map data; 50 Map data;
45 51
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 if (path.startsWith('/')) { 280 if (path.startsWith('/')) {
275 return "$pageDomain$path"; 281 return "$pageDomain$path";
276 } else if (path.startsWith("#")) { 282 } else if (path.startsWith("#")) {
277 return "$pageUrl$path"; 283 return "$pageUrl$path";
278 } else { 284 } else {
279 return "$pageDir$path"; 285 return "$pageDir$path";
280 } 286 }
281 } 287 }
282 288
283 bool inTable(Node n) { 289 bool inTable(Node n) {
284 while(n != null) { 290 while (n != null) {
285 if (n is TableElement) return true; 291 if (n is TableElement) return true;
286 n = n.parent; 292 n = n.parent;
287 } 293 }
288 return false; 294 return false;
289 } 295 }
290 296
291 String escapeHTML(str) { 297 String escapeHTML(str) {
292 Element e = new Element.tag("div"); 298 Element e = new Element.tag("div");
293 e.text = str; 299 e.text = str;
294 return e.innerHTML; 300 return e.innerHTML;
295 } 301 }
296 302
297 List<Text> getAllTextNodes(Element elem) { 303 List<Text> getAllTextNodes(Element elem) {
298 List<Text> nodes = <Text>[]; 304 final nodes = <Text>[];
299 helper(Node n) { 305 helper(Node n) {
300 if (n is Text) { 306 if (n is Text) {
301 nodes.add(n); 307 nodes.add(n);
302 } else { 308 } else {
303 for (Node child in n.nodes) { 309 for (Node child in n.nodes) {
304 helper(child); 310 helper(child);
305 } 311 }
306 } 312 }
307 }; 313 };
308 314
309 helper(elem); 315 helper(elem);
310 return nodes; 316 return nodes;
311 } 317 }
312 318
313 /** 319 /**
314 * Whether a node and its children are all types that are safe to skip if the 320 * Whether a node and its children are all types that are safe to skip if the
315 * nodes have no text content. 321 * nodes have no text content.
316 */ 322 */
317 bool isSkippableType(Node n) { 323 bool isSkippableType(Node n) {
318 // TODO(jacobr): are there any types we don't want to skip even if they 324 // TODO(jacobr): are there any types we don't want to skip even if they
319 // have no text content? 325 // have no text content?
320 if (n is ImageElement || n is CanvasElement || n is InputElement 326 if (n is ImageElement || n is CanvasElement || n is InputElement
321 || n is ObjectElement) { 327 || n is ObjectElement) {
322 return false; 328 return false;
323 } 329 }
324 if (n is Text) return true; 330 if (n is Text) return true;
325 331
326 for (Node child in n.nodes) { 332 for (final child in n.nodes) {
327 if (isSkippableType(child) == false) { 333 if (!isSkippableType(child)) {
328 return false; 334 return false;
329 } 335 }
330 } 336 }
331 return true; 337 return true;
332 } 338 }
333 339
334 bool isSkippable(Node n) { 340 bool isSkippable(Node n) {
335 if (!isSkippableType(n)) return false; 341 if (!isSkippableType(n)) return false;
336 return n.text.trim().length == 0; 342 return n.text.trim().length == 0;
337 } 343 }
338 344
339 void onEnd() { 345 void onEnd() {
340 // Hideous hack to send JSON back to JS. 346 // Hideous hack to send JSON back to JS.
341 String dbJson = JSON.stringify(dbEntry); 347 String dbJson = JSON.stringify(dbEntry);
342 // workaround bug in JSON parser. 348 // workaround bug in JSON parser.
343 dbJson = dbJson.replaceAll("ZDARTIUMDOESNTESCAPESLASHNJXXXX", "\\n"); 349 dbJson = dbJson.replaceAll("ZDARTIUMDOESNTESCAPESLASHNJXXXX", "\\n");
344 350
345 window.postMessage("START_DART_MESSAGE_UNIQUE_IDENTIFIER$dbJson", "*"); 351 window.postMessage("START_DART_MESSAGE_UNIQUE_IDENTIFIER$dbJson", "*");
346 } 352 }
347 353
348 class SectionParseResult { 354 class SectionParseResult {
349 final String html; 355 final String html;
350 final String url; 356 final String url;
351 final String idl; 357 final String idl;
352 SectionParseResult(this.html, this.url, this.idl); 358 SectionParseResult(this.html, this.url, this.idl);
353 } 359 }
354 360
355 String genCleanHtml(Element root) { 361 String genCleanHtml(Element root) {
356 for (Element e in root.queryAll(".$DART_REMOVED")) { 362 for (final e in root.queryAll(".$DART_REMOVED")) {
357 e.classes.remove(DART_REMOVED); 363 e.classes.remove(DART_REMOVED);
358 } 364 }
359 365
360 // Ditch inline styles. 366 // Ditch inline styles.
361 for (Element e in root.queryAll('[style]')) { 367 for (final e in root.queryAll('[style]')) {
362 e.attributes.remove('style'); 368 e.attributes.remove('style');
363 } 369 }
364 370
365 // These elements are just tags that we should suppress. 371 // These elements are just tags that we should suppress.
366 for (Element e in root.queryAll(".lang.lang-en")) { 372 for (final e in root.queryAll(".lang.lang-en")) {
367 e.remove(); 373 e.remove();
368 } 374 }
369 375
376 Element parametersList;
377 Element returnValue;
nweiz 2012/02/02 00:16:19 Maybe "parametersHeader" and "returnHeader"? Curre
378 for (final e in root.queryAll("h6")) {
379 if (e.text == 'Parameters') {
380 parametersList = e;
381 } else if (e.text == 'Return value') {
382 returnValue = e;
383 }
384 }
385
386 if (parametersList != null) {
387 int numEmptyParameters = 0;
388 final parameterDescriptions = root.queryAll("dd");
389 for (Element parameterDescription in parameterDescriptions) {
390 if (parameterDescription.text.trim().length == 0) {
391 numEmptyParameters++;
nweiz 2012/02/02 00:16:19 "numEmptyParameters = parameterDescriptions.filter
392 }
393 }
394 if (numEmptyParameters > 0 &&
395 numEmptyParameters == parameterDescriptions.length) {
396 // Remove the parameter list as it adds zero value as all descriptions
397 // are empty.
398 parametersList.remove();
399 for (final e in root.queryAll("dl")) {
400 e.remove();
401 }
402 } else if (parameterDescriptions.length == 0 &&
403 parametersList.nextElementSibling != null &&
404 parametersList.nextElementSibling.text.trim() == 'None.') {
405 // No need to display that the function takes 0 parameters.
406 parametersList.nextElementSibling.remove();
407 parametersList.remove();
408 }
409 }
410
411 // Heuristic: if the return value is a single word it is a type name not a
412 // useful text description so suppress it.
413 if (returnValue != null &&
414 returnValue.nextElementSibling != null &&
415 returnValue.nextElementSibling.text.trim().split(' ').length <= 1) {
416 returnValue.nextElementSibling.remove();
417 returnValue.remove();
418 }
419
370 bool changed = true; 420 bool changed = true;
371 while (changed) { 421 while (changed) {
372 changed = false; 422 changed = false;
373 while (root.nodes.length == 1) { 423 while (root.nodes.length == 1 && root.nodes.first is Element) {
374 Node child = root.nodes.first; 424 root = root.nodes.first;
375 if (child is Element) { 425 changed = true;
376 root = child;
377 changed = true;
378 } else {
379 // Just calling innerHTML on the parent will be sufficient...
380 // and insures the output is properly escaped.
381 break;
382 }
383 } 426 }
384 427
385 // Trim useless nodes from the front. 428 // Trim useless nodes from the front.
386 while(root.nodes.length > 0 && 429 while (root.nodes.length > 0 &&
387 isSkippable(root.nodes.first)) { 430 isSkippable(root.nodes.first)) {
388 root.nodes.first.remove(); 431 root.nodes.first.remove();
389 changed = true; 432 changed = true;
390 } 433 }
391 434
392 // Trim useless nodes from the back. 435 // Trim useless nodes from the back.
393 while(root.nodes.length > 0 && 436 while (root.nodes.length > 0 &&
394 isSkippable(root.nodes.last())) { 437 isSkippable(root.nodes.last())) {
395 root.nodes.last().remove(); 438 root.nodes.last().remove();
396 changed = true; 439 changed = true;
397 } 440 }
398 } 441 }
399 return JSONFIXUPHACK(root.innerHTML); 442 return JSONFIXUPHACK(root.innerHTML);
400 } 443 }
401 444
402 String genPrettyHtml(DocumentFragment fragment) {
403 return genCleanHtml(fragment);
404 }
405
406 String genPrettyHtmlFromElement(Element e) { 445 String genPrettyHtmlFromElement(Element e) {
407 e = e.clone(true); 446 e = e.clone(true);
408 return genCleanHtml(e); 447 return genCleanHtml(e);
409 } 448 }
410 449
411 class PostOrderTraversalIterator implements Iterator<Node> { 450 class PostOrderTraversalIterator implements Iterator<Node> {
412 451
413 Node _next; 452 Node _next;
414 453
415 PostOrderTraversalIterator(Node start) { 454 PostOrderTraversalIterator(Node start) {
416 _next = _leftMostDescendent(start); 455 _next = _leftMostDescendent(start);
417 } 456 }
418 457
419 bool hasNext() => _next != null; 458 bool hasNext() => _next != null;
420 459
421 Node next() { 460 Node next() {
422 if (_next == null) return null; 461 if (_next == null) return null;
423 Node ret = _next; 462 final ret = _next;
424 if (_next.nextNode != null) { 463 if (_next.nextNode != null) {
425 _next = _leftMostDescendent(_next.nextNode); 464 _next = _leftMostDescendent(_next.nextNode);
426 } else { 465 } else {
427 _next = _next.parent; 466 _next = _next.parent;
428 } 467 }
429 return ret; 468 return ret;
430 } 469 }
431 470
432 static Node _leftMostDescendent(Node n) { 471 static Node _leftMostDescendent(Node n) {
433 while (n.nodes.length > 0) { 472 while (n.nodes.length > 0) {
434 n = n.nodes.first; 473 n = n.nodes.first;
435 } 474 }
436 return n; 475 return n;
437 } 476 }
438 } 477 }
439 478
440 class PostOrderTraversal implements Iterable<Node> { 479 class PostOrderTraversal implements Iterable<Node> {
441 final Node _node; 480 final Node _node;
442 PostOrderTraversal(this._node); 481 PostOrderTraversal(this._node);
443 482
444 Iterator<Node> iterator() => new PostOrderTraversalIterator(_node); 483 Iterator<Node> iterator() => new PostOrderTraversalIterator(_node);
445 } 484 }
446 485
447 Range findFirstLine(Range section, String prop) { 486 Range findFirstLine(Range section, String prop) {
448 Range firstLine = newRange(); 487 final firstLine = newRange();
449 firstLine.setStart(section.startContainer, section.startOffset); 488 firstLine.setStart(section.startContainer, section.startOffset);
450 489
451 num maxBottom = null; 490 num maxBottom = null;
452 for (Node n in new PostOrderTraversal(section.startContainer)) { 491 for (final n in new PostOrderTraversal(section.startContainer)) {
453 int compareResult = section.comparePoint(n, 0); 492 int compareResult = section.comparePoint(n, 0);
454 if (compareResult == -1) { 493 if (compareResult == -1) {
455 // before range so skip. 494 // before range so skip.
456 continue; 495 continue;
457 } else if (compareResult > 0) { 496 } else if (compareResult > 0) {
458 // After range so exit. 497 // After range so exit.
459 break; 498 break;
460 } 499 }
461 500
462 final rect = getClientRect(n); 501 final rect = getClientRect(n);
463 num bottom = rect.bottom; 502 num bottom = rect.bottom;
464 if (rect.height > 0 && rect.width > 0) { 503 if (rect.height > 0 && rect.width > 0) {
465 if (maxBottom != null && ( 504 if (maxBottom != null &&
466 maxBottom + MIN_PIXELS_DIFFERENT_LINES < bottom 505 maxBottom + MIN_PIXELS_DIFFERENT_LINES < bottom) {
467 )) {
468 break; 506 break;
469 } else if (maxBottom == null || maxBottom > bottom) { 507 } else if (maxBottom == null || maxBottom > bottom) {
470 maxBottom = bottom; 508 maxBottom = bottom;
471 } 509 }
472 } 510 }
473 511
474 firstLine.setEndAfter(n); 512 firstLine.setEndAfter(n);
475 } 513 }
476 514
477 if (firstLine.toString().indexOf(stripWebkit(prop)) == -1) { 515 // If the first line of text in the section does not contain the property
516 // name then we're not confident we are able to extract a high accuracy match
517 // so we should not return anything.
518 if (!firstLine.toString().contains(stripWebkit(prop))) {
478 return null; 519 return null;
479 } 520 }
480 return firstLine; 521 return firstLine;
481 } 522 }
482 523
483 AnchorElement findAnchorElement(Element root, String prop) { 524 AnchorElement findAnchorElement(Element root, String prop) {
484 for (AnchorElement a in root.queryAll("a")) { 525 for (AnchorElement a in root.queryAll("a")) {
485 if (a.text.indexOf(prop) != -1) { 526 if (a.text.contains(prop)) {
486 return a; 527 return a;
487 } 528 }
488 } 529 }
489 return null; 530 return null;
490 } 531 }
491 532
492 // First surrounding element with an ID is safe enough. 533 // First surrounding element with an ID is safe enough.
493 Element findTigherRoot(Element elem, Element root) { 534 Element findTighterRoot(Element elem, Element root) {
494 Element candidate = elem; 535 Element candidate = elem;
495 while(root != candidate) { 536 while (root != candidate) {
496 candidate = candidate.parent; 537 candidate = candidate.parent;
497 if (candidate.id.length > 0 && candidate.id.indexOf("section_") != 0) { 538 if (candidate.id.length > 0 && candidate.id.indexOf("section_") != 0) {
498 break; 539 break;
499 } 540 }
500 } 541 }
501 return candidate; 542 return candidate;
502 } 543 }
503 544
504 // this is very slow and ugly.. consider rewriting. 545 // TODO(jacobr): this is very slow and ugly.. consider rewriting or at least
546 // commenting carefully.
505 SectionParseResult filteredHtml(Element elem, Element root, String prop, 547 SectionParseResult filteredHtml(Element elem, Element root, String prop,
506 Function fragmentGeneratedCallback) { 548 Function fragmentGeneratedCallback) {
507 // Using a tighter root avoids false positives at the risk of trimming 549 // Using a tighter root avoids false positives at the risk of trimming
508 // text we shouldn't. 550 // text we shouldn't.
509 root = findTigherRoot(elem, root); 551 root = findTighterRoot(elem, root);
510 Range range = newRange(); 552 final range = newRange();
511 range.setStartBefore(elem); 553 range.setStartBefore(elem);
512 554
513 Element current = elem; 555 Element current = elem;
514 while (current != null) { 556 while (current != null) {
515 range.setEndBefore(current); 557 range.setEndBefore(current);
516 if (current.classes.contains(DART_REMOVED)) { 558 if (current.classes.contains(DART_REMOVED) &&
517 if (range.toString().trim().length > 0) { 559 range.toString().trim().length > 0) {
518 break; 560 break;
519 }
520 } 561 }
521 if (current.firstElementChild != null) { 562 if (current.firstElementChild != null) {
522 current = current.firstElementChild; 563 current = current.firstElementChild;
523 } else { 564 } else {
524 while (current != null) { 565 while (current != null) {
525 range.setEndAfter(current); 566 range.setEndAfter(current);
526 if (current == root) { 567 if (current == root) {
527 current = null; 568 current = null;
528 break; 569 break;
529 } 570 }
(...skipping 10 matching lines...) Expand all
540 Range firstLine = findFirstLine(range, prop); 581 Range firstLine = findFirstLine(range, prop);
541 if (firstLine != null) { 582 if (firstLine != null) {
542 range.setStart(firstLine.endContainer, firstLine.endOffset); 583 range.setStart(firstLine.endContainer, firstLine.endOffset);
543 DocumentFragment firstLineClone = firstLine.cloneContents(); 584 DocumentFragment firstLineClone = firstLine.cloneContents();
544 AnchorElement anchor = findAnchorElement(firstLineClone, prop); 585 AnchorElement anchor = findAnchorElement(firstLineClone, prop);
545 if (anchor != null) { 586 if (anchor != null) {
546 url = getAbsoluteUrl(anchor); 587 url = getAbsoluteUrl(anchor);
547 } 588 }
548 } 589 }
549 } 590 }
550 DocumentFragment fragment = range.cloneContents(); 591 final fragment = range.cloneContents();
551 if (fragmentGeneratedCallback != null) { 592 if (fragmentGeneratedCallback != null) {
552 fragmentGeneratedCallback(fragment); 593 fragmentGeneratedCallback(fragment);
553 } 594 }
554 // Strip tags we don't want 595 // Strip tags we don't want
555 for (Element e in fragment.queryAll("script, object, style")) { 596 for (Element e in fragment.queryAll("script, object, style")) {
556 e.remove(); 597 e.remove();
557 } 598 }
558 599
559 // Extract idl 600 // Extract idl
560 StringBuffer idl = new StringBuffer(); 601 final idl = new StringBuffer();
561 if (prop != null && prop.length > 0) { 602 if (prop != null && prop.length > 0) {
562 // Only expect properties to have HTML. 603 // Only expect properties to have HTML.
563 for(Element e in fragment.queryAll(IDL_SELECTOR)) { 604 for(Element e in fragment.queryAll(IDL_SELECTOR)) {
564 idl.add(e.outerHTML); 605 idl.add(e.outerHTML);
565 e.remove(); 606 e.remove();
566 } 607 }
567 // TODO(jacobr) this is a very basic regex to see if text looks like IDL 608 // TODO(jacobr) this is a very basic regex to see if text looks like IDL
568 RegExp likelyIdl = new RegExp(" $prop\\w*\\("); 609 RegExp likelyIdl = new RegExp(" $prop\\w*\\(");
569 610
570 for (Element e in fragment.queryAll("pre")) { 611 for (Element e in fragment.queryAll("pre")) {
571 // Check if it looks like idl... 612 // Check if it looks like idl...
572 String txt = e.text.trim(); 613 String txt = e.text.trim();
573 if (likelyIdl.hasMatch(txt) && txt.indexOf("\n") != -1 614 if (likelyIdl.hasMatch(txt) && txt.contains("\n") && txt.contains(")")) {
574 && txt.indexOf(")") != -1) {
575 idl.add(e.outerHTML); 615 idl.add(e.outerHTML);
576 e.remove(); 616 e.remove();
577 } 617 }
578 } 618 }
579 } 619 }
580 return new SectionParseResult(genPrettyHtml(fragment), url, idl.toString()); 620 return new SectionParseResult(genCleanHtml(fragment), url, idl.toString());
581 } 621 }
582 622
583 Element findBest(Element root, List<Text> allText, String prop, String propType) { 623 Element findBest(Element root, List<Text> allText, String prop,
624 String propType) {
584 // Best bet: match an id 625 // Best bet: match an id
585 Element cand; 626 Element cand;
586 cand = root.query("#" + prop); 627 cand = root.query("#$prop");
587 628
588 if (cand == null && propType == "methods") { 629 if (cand == null && propType == "methods") {
589 cand = root.query("[id=" + prop + "\\(\\)]"); 630 cand = root.query("[id=$prop\\(\\)]");
631 }
632 while (cand != null && cand.text.trim().length == 0) {
633 // We found the bookmark for the element but sadly it is just an empty
634 // placeholder. Find the first real element.
635 cand = cand.nextElementSibling;
590 } 636 }
591 if (cand != null) { 637 if (cand != null) {
592 while (cand != null && cand.text.trim().length == 0) { 638 return cand;
593 // We found the bookmark for the element but sadly it is just an empty
594 // placeholder. Find the first real element.
595 cand = cand.nextElementSibling;
596 }
597 if (cand != null) {
598 return cand;
599 }
600 } 639 }
601 640
602 // If you are at least 70 pixels from the left, something is definitely fishy and we shouldn't even consider this candidate. 641 // If you are at least 70 pixels from the left, something is definitely
642 // fishy and we shouldn't even consider this candidate.
603 num candLeft = 70; 643 num candLeft = 70;
604 644
605 for (Text text in allText) { 645 for (Text text in allText) {
606 Element proposed = null; 646 Element proposed = null;
607 647
608 // var t = safeNameCleanup(text.text); 648 // TODO(jacobr): does it hurt precision to use the full cleanup?
609 // TODO(jacobr): does it hurt precision to use the full cleanup?
610 String t = fullNameCleanup(text.text); 649 String t = fullNameCleanup(text.text);
611 if (t == prop) { 650 if (t == prop) {
612 proposed = text.parent; 651 proposed = text.parent;
613 ClientRect candRect = getClientRect(proposed); 652 ClientRect candRect = getClientRect(proposed);
614 653
615 // TODO(jacobr): this is a good heuristic 654 // TODO(jacobr): this is a good heuristic
616 // if (selObj.selector.indexOf(" > DD ") == -1 655 // if (selObj.selector.indexOf(" > DD ") == -1
617 if (candRect.left < candLeft) { 656 if (candRect.left < candLeft) {
618 cand = proposed; 657 cand = proposed;
619 candLeft = candRect.left; 658 candLeft = candRect.left;
620 } 659 }
621 } 660 }
622 } 661 }
623 return cand; 662 return cand;
624 } 663 }
625 664
626 bool isObsolete(Element e) { 665 bool isObsolete(Element e) {
627 RegExp obsoleteRegExp = new RegExp(@"(^|\s)obsolete(?=\s|$)"); 666 RegExp obsoleteRegExp = new RegExp(@"(^|\s)obsolete(?=\s|$)");
628 RegExp deprecatedRegExp = new RegExp(@"(^|\s)deprecated(?=\s|$)"); 667 RegExp deprecatedRegExp = new RegExp(@"(^|\s)deprecated(?=\s|$)");
629 for (Element child in e.queryAll("span")) { 668 for (Element child in e.queryAll("span")) {
630 String t = child.text.toLowerCase(); 669 String t = child.text.toLowerCase();
631 if (t.startsWith("obsolete") || t.startsWith("deprecated")) return true; 670 if (t.startsWith("obsolete") || t.startsWith("deprecated")) return true;
632 } 671 }
633 672
634 String text = e.text.toLowerCase(); 673 String text = e.text.toLowerCase();
635 return obsoleteRegExp.hasMatch(text) || deprecatedRegExp.hasMatch(text); 674 return obsoleteRegExp.hasMatch(text) || deprecatedRegExp.hasMatch(text);
636 } 675 }
637 676
638 bool isFirstCharLowerCase(String str) { 677 bool isFirstCharLowerCase(String str) {
639 RegExp firstLower = new RegExp("^[a-z]"); 678 return const RegExp("^[a-z]").hasMatch(str);
640 return firstLower.hasMatch(str);
641 } 679 }
642 680
643 void scrapeSection(Element root, String sectionSelector, 681 // TODO(jacobr): document this method.
644 String currentType, 682 void scrapeSection(Element root, String sectionSelector, String currentType,
645 List members, 683 List members, String propType) {
646 String propType) {
647 Map expectedProps = dartIdl[propType]; 684 Map expectedProps = dartIdl[propType];
648 685
649 Set<String> alreadyMatchedProperties = new Set<String>(); 686 Set<String> alreadyMatchedProperties = new Set<String>();
650 bool onlyConsiderTables = false; 687 bool onlyConsiderTables = false;
651 ElementList allMatches = root.queryAll(sectionSelector); 688 ElementList allMatches = root.queryAll(sectionSelector);
652 if (allMatches.length == 0) { 689 if (allMatches.length == 0) {
653 allMatches = root.queryAll(".fullwidth-table"); 690 allMatches = root.queryAll(".fullwidth-table");
654 onlyConsiderTables = true; 691 onlyConsiderTables = true;
655 } 692 }
656 for (Element matchElement in allMatches) { 693 for (Element matchElement in allMatches) {
657 DivElement match = matchElement.parent; 694 DivElement match = matchElement.parent;
658 if (!match.id.startsWith("section") && !(match.id == "pageText")) { 695 if (!match.id.startsWith("section") && match.id != "pageText") {
659 throw "Enexpected element $match"; 696 throw "Unexpected element $match";
660 } 697 }
661 match.classes.add(DART_REMOVED); 698 match.classes.add(DART_REMOVED);
662 699
663 bool foundProps = false; 700 bool foundProps = false;
664 701
665 // TODO(jacobr): we should really look for the table tag instead 702 // TODO(jacobr): we should really look for the table tag instead
666 // add an assert if we are missing something that is a table... 703 // add an assert if we are missing something that is a table...
667 // TODO(jacobr) ignore tables in tables.... 704 // TODO(jacobr) ignore tables in tables....
668 for (Element t in match.queryAll('.standard-table, .fullwidth-table')) { 705 for (Element t in match.queryAll('.standard-table, .fullwidth-table')) {
669 int helpIndex = -1; 706 int helpIndex = -1;
670 num i = 0; 707 num i = 0;
671 for (Element r in t.queryAll("th, td.header")) { 708 for (Element r in t.queryAll("th, td.header")) {
672 var txt = r.text.trim().split(" ")[0].toLowerCase(); 709 final txt = r.text.trim().split(" ")[0].toLowerCase();
673 if (txt == "description") { 710 if (txt == "description") {
674 helpIndex = i; 711 helpIndex = i;
675 break; 712 break;
676 } 713 }
677 i++; 714 i++;
678 } 715 }
679 716
680 List<int> numMatches = new List<int>(i); 717 List<int> numMatches = new List<int>(i);
681 for (int j = 0; j < i; j++) { 718 for (int j = 0; j < i; j++) {
682 numMatches[j] = 0; 719 numMatches[j] = 0;
683 } 720 }
684 721
685 // Find the row that seems to have the most names that look like 722 // Find the row that seems to have the most names that look like
686 // expected properties. 723 // expected properties.
687 for (Element r in t.queryAll("tbody tr")) { 724 for (Element r in t.queryAll("tbody tr")) {
688 ElementList $row = r.elements; 725 ElementList row = r.elements;
689 if ($row.length == 0 || $row.first.classes.contains(".header")) { 726 if (row.length == 0 || row.first.classes.contains(".header")) {
690 continue; 727 continue;
691 } 728 }
692 729
693 for (int k = 0; k < numMatches.length && k < $row.length; k++) { 730 for (int k = 0; k < numMatches.length && k < row.length; k++) {
694 Element e = $row[k]; 731 if (expectedProps.containsKey(fullNameCleanup(row[k].text))) {
695 if (expectedProps.containsKey(fullNameCleanup(e.text))) {
696 numMatches[k]++; 732 numMatches[k]++;
697 break; 733 break;
698 } 734 }
699 } 735 }
700 } 736 }
701 737
702 int propNameIndex = 0; 738 int propNameIndex = 0;
703 { 739 {
704 int bestCount = numMatches[0]; 740 int bestCount = numMatches[0];
705 for (int k = 1; k < numMatches.length; k++) { 741 for (int k = 1; k < numMatches.length; k++) {
706 if (numMatches[k] > bestCount) { 742 if (numMatches[k] > bestCount) {
707 bestCount = numMatches[k]; 743 bestCount = numMatches[k];
708 propNameIndex = k; 744 propNameIndex = k;
709 } 745 }
710 } 746 }
711 } 747 }
712 748
713 for (Element r in t.queryAll("tbody tr")) { 749 for (Element r in t.queryAll("tbody tr")) {
714 ElementList $row = r.elements; 750 ElementList row = r.elements;
715 if ($row.length > propNameIndex && $row.length > helpIndex ) { 751 if (row.length > propNameIndex && row.length > helpIndex) {
716 if ($row.first.classes.contains(".header")) { 752 if (row.first.classes.contains(".header")) {
717 continue; 753 continue;
718 } 754 }
719 // TODO(jacobr): this code for determining the namestr is needlessly 755 // TODO(jacobr): this code for determining the namestr is needlessly
720 // messy. 756 // messy.
721 Element nameRow = $row[propNameIndex]; 757 Element nameRow = row[propNameIndex];
722 AnchorElement a = nameRow.query("a"); 758 AnchorElement a = nameRow.query("a");
723 String goodName = ''; 759 String goodName = '';
724 if (a != null) { 760 if (a != null) {
725 goodName = a.text.trim(); 761 goodName = a.text.trim();
726 } 762 }
727 String nameStr = nameRow.text; 763 String nameStr = nameRow.text;
728 764
729 Map entry = new Map<String, String>(); 765 Map entry = new Map<String, String>();
730 766
731 // "currentType": $($row[1]).text().trim(), // find("code") ? 767 entry["name"] = fullNameCleanup(nameStr.length > 0 ?
732 entry["name"] = fullNameCleanup(nameStr.length > 0 ? nameStr : goodNam e); 768 nameStr : goodName);
733 769
734 final parse = filteredHtml(nameRow, nameRow, entry["name"], null); 770 final parse = filteredHtml(nameRow, nameRow, entry["name"], null);
735 String altHelp = parse.html; 771 String altHelp = parse.html;
736 772
737 // "jsSignature": nameStr, 773 entry["help"] = (helpIndex == -1 || row[helpIndex] == null) ?
738 entry["help"] = (helpIndex == -1 || $row[helpIndex] == null) ? altHelp : genPrettyHtmlFromElement($row[helpIndex]); 774 altHelp : genPrettyHtmlFromElement(row[helpIndex]);
739 // "altHelp" : altHelp,
740 if (parse.url != null) { 775 if (parse.url != null) {
741 entry["url"] = parse.url; 776 entry["url"] = parse.url;
742 } 777 }
743 778
744 if (parse.idl.length > 0) { 779 if (parse.idl.length > 0) {
745 entry["idl"] = parse.idl; 780 entry["idl"] = parse.idl;
746 } 781 }
747 782
748 entry["obsolete"] = isObsolete(r); 783 entry["obsolete"] = isObsolete(r);
749 784
(...skipping 20 matching lines...) Expand all
770 if (alreadyMatchedProperties.contains(prop)) { 805 if (alreadyMatchedProperties.contains(prop)) {
771 continue; 806 continue;
772 } 807 }
773 Element e = findBest(match, allText, prop, propType); 808 Element e = findBest(match, allText, prop, propType);
774 if (e != null && !inTable(e)) { 809 if (e != null && !inTable(e)) {
775 pmap[prop] = e; 810 pmap[prop] = e;
776 } 811 }
777 } 812 }
778 813
779 for (String prop in pmap.getKeys()) { 814 for (String prop in pmap.getKeys()) {
780 Element e = pmap[prop]; 815 pmap[prop].classes.add(DART_REMOVED);
781 e.classes.add(DART_REMOVED);
782 } 816 }
783 817
784 for (String prop in pmap.getKeys()) { 818 for (String prop in pmap.getKeys()) {
785 Element e = pmap[prop]; 819 Element e = pmap[prop];
786 ClientRect r = getClientRect(e); 820 ClientRect r = getClientRect(e);
787 // TODO(jacobr): a lot of these queries are identical. 821 // TODO(jacobr): a lot of these queries are identical.
788 for (Element cand in match.queryAll(e.tagName)) { 822 for (Element cand in match.queryAll(e.tagName)) {
789 if (!cand.classes.contains(DART_REMOVED) && !inTable(cand) ) { // XXX us e a neg selector. 823 // TODO(jacobr): use a negative selector instead.
824 if (!cand.classes.contains(DART_REMOVED) && !inTable(cand)) {
790 ClientRect candRect = getClientRect(cand); 825 ClientRect candRect = getClientRect(cand);
791 // TODO(jacobr): this is somewhat loose. 826 // TODO(jacobr): this is somewhat loose.
792 if (candRect.left == r.left && 827 if (candRect.left == r.left &&
793 (candRect.height - r.height).abs() < 5) { 828 (candRect.height - r.height).abs() < 5) {
794 String propName = fullNameCleanup(cand.text); 829 String propName = fullNameCleanup(cand.text);
795 if (isFirstCharLowerCase(propName) && pmap.containsKey(propName) == false && alreadyMatchedProperties.contains(propName) == false) { 830 if (isFirstCharLowerCase(propName) && !pmap.containsKey(propName)
796 // Don't set here to avoid layouts... cand.classes.add(DART_REMOVE D); 831 && !alreadyMatchedProperties.contains(propName)) {
797 pmap[propName] = cand; 832 pmap[propName] = cand;
798 } 833 }
799 } 834 }
800 } 835 }
801 } 836 }
802 } 837 }
803 838
804 for (String prop in pmap.getKeys()) { 839 for (String prop in pmap.getKeys()) {
805 Element e = pmap[prop]; 840 Element e = pmap[prop];
806 e.classes.add(DART_REMOVED); 841 e.classes.add(DART_REMOVED);
807 } 842 }
808 843
809 // Find likely "subsections" of the main section and mark them with 844 // Find likely "subsections" of the main section and mark them with
810 // DART_REMOVED so we don't include them in member descriptions... which 845 // DART_REMOVED so we don't include them in member descriptions... which
811 // would suck. 846 // would suck.
812 for (Element e in match.queryAll("[id]")) { 847 for (Element e in match.queryAll("[id]")) {
813 if (e.id.indexOf(matchElement.id) != -1) { 848 if (e.id.contains(matchElement.id)) {
814 e.classes.add(DART_REMOVED); 849 e.classes.add(DART_REMOVED);
815 } 850 }
816 } 851 }
817 852
818 for (String prop in pmap.getKeys()) { 853 for (String prop in pmap.getKeys()) {
819 Element elem = pmap[prop]; 854 Element elem = pmap[prop];
820 bool obsolete = false; 855 bool obsolete = false;
821 final parse = filteredHtml( 856 final parse = filteredHtml(
822 elem, match, prop, 857 elem, match, prop,
823 (Element e) { 858 (Element e) {
824 obsolete = isObsolete(e); 859 obsolete = isObsolete(e);
825 }); 860 });
826 Map entry = { 861 Map entry = {
827 "url" : parse.url, 862 "url" : parse.url,
828 "name" : prop, 863 "name" : prop,
829 "help" : parse.html, 864 "help" : parse.html,
830 "obsolete" : obsolete 865 "obsolete" : obsolete
831 //"jsSignature" : nameStr
832 }; 866 };
833 if (parse.idl.length > 0) { 867 if (parse.idl.length > 0) {
834 entry["idl"] = parse.idl; 868 entry["idl"] = parse.idl;
835 } 869 }
836 cleanupEntry(members, entry); 870 cleanupEntry(members, entry);
837 } 871 }
838 } 872 }
839 } 873 }
840 874
841 String trimHtml(String html) { 875 String trimHtml(String html) {
842 // TODO(jacobr): impl. 876 // TODO(jacobr): impl.
843 return html; 877 return html;
844 } 878 }
845 879
846 bool maybeName(String name) { 880 bool maybeName(String name) {
847 RegExp nameRegExp = new RegExp("^[a-z][a-z0-9A-Z]+\$"); 881 return const RegExp("^[a-z][a-z0-9A-Z]+\$").hasMatch(name) ||
848 if (nameRegExp.hasMatch(name)) return true; 882 const RegExp("^[A-Z][A-Z_]*\$").hasMatch(name);
849 RegExp constRegExp = new RegExp("^[A-Z][A-Z_]*\$");
850 if (constRegExp.hasMatch(name)) return true;
851 } 883 }
852 884
853 void markRemoved(var e) { 885 void markRemoved(var e) {
854 if (e != null) { 886 if (e != null) {
855 // TODO( remove) 887 // TODO( remove)
856 if (e is Element) { 888 if (e is Element) {
857 e.classes.add(DART_REMOVED); 889 e.classes.add(DART_REMOVED);
858 } else { 890 } else {
859 for (Element el in e) { 891 for (Element el in e) {
860 el.classes.add(DART_REMOVED); 892 el.classes.add(DART_REMOVED);
861 } 893 }
862 } 894 }
863 } 895 }
864 } 896 }
865 897
866 String JSONFIXUPHACK(String value) { 898 String JSONFIXUPHACK(String value) {
867 return value.replaceAll("\n", "ZDARTIUMDOESNTESCAPESLASHNJXXXX"); 899 return value.replaceAll("\n", "ZDARTIUMDOESNTESCAPESLASHNJXXXX");
868 } 900 }
869 901
870 String mozToWebkit(String name) { 902 String mozToWebkit(String name) {
871 RegExp regExp = new RegExp("^moz"); 903 return name.replaceFirst(const RegExp("^moz"), "webkit");
872 name = name.replaceFirst(regExp, "webkit");
873 return name;
874 } 904 }
875 905
876 String stripWebkit(String name) { 906 String stripWebkit(String name) {
877 return trimPrefix(name, "webkit"); 907 return trimPrefix(name, "webkit");
878 } 908 }
879 909
880 String fullNameCleanup(String name) { 910 String fullNameCleanup(String name) {
881 int parenIndex = name.indexOf('('); 911 int parenIndex = name.indexOf('(');
882 if (parenIndex != -1) { 912 if (parenIndex != -1) {
883 // TODO(jacobr): workaround bug in: 913 // TODO(jacobr): workaround bug in:
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 973
944 // TODO(jacobr) dup with trim start.... 974 // TODO(jacobr) dup with trim start....
945 String trimPrefix(String str, String prefix) { 975 String trimPrefix(String str, String prefix) {
946 if (str.indexOf(prefix) == 0) { 976 if (str.indexOf(prefix) == 0) {
947 return str.substring(prefix.length); 977 return str.substring(prefix.length);
948 } else { 978 } else {
949 return str; 979 return str;
950 } 980 }
951 } 981 }
952 982
953 void resourceLoaded() {
954 if (data != null) run();
955 }
956
957 String trimStart(String str, String start) { 983 String trimStart(String str, String start) {
958 if (str.startsWith(start) && str.length > start.length) { 984 if (str.startsWith(start) && str.length > start.length) {
959 return str.substring(start.length); 985 return str.substring(start.length);
960 } 986 }
961 return str; 987 return str;
962 } 988 }
963 989
964 String trimEnd(String str, String end) { 990 String trimEnd(String str, String end) {
965 if (str.endsWith(end) && str.length > end.length) { 991 if (str.endsWith(end) && str.length > end.length) {
966 return str.substring(0, str.length - end.length); 992 return str.substring(0, str.length - end.length);
(...skipping 13 matching lines...) Expand all
980 dbEntry[key] += html; 1006 dbEntry[key] += html;
981 } else { 1007 } else {
982 dbEntry[key] = html; 1008 dbEntry[key] = html;
983 } 1009 }
984 } 1010 }
985 e.classes.add(DART_REMOVED); 1011 e.classes.add(DART_REMOVED);
986 } 1012 }
987 } 1013 }
988 1014
989 void run() { 1015 void run() {
990 // Inject CSS to insure lines don't wrap unless it was intentional. 1016 // Inject CSS to ensure lines don't wrap unless it was intentional.
991 document.head.nodes.add(new Element.html(""" 1017 document.head.nodes.add(new Element.html("""
992 <style type="text/css"> 1018 <style type="text/css">
993 body { 1019 body {
994 width: 10000px; 1020 width: 10000px;
995 } 1021 }
996 </style>""")); 1022 </style>"""));
997 1023
998 String title = trimEnd(window.document.title.trim(), " - MDN"); 1024 String title = trimEnd(window.document.title.trim(), " - MDN");
999 dbEntry['title'] = title; 1025 dbEntry['title'] = title;
1000 1026
1001 // TODO(rnystrom): Clean up the page a bunch. Not sure if this is the best 1027 // TODO(rnystrom): Clean up the page a bunch. Not sure if this is the best
1002 // place to do this... 1028 // place to do this...
1003 1029
1004 // Remove the "Introduced in HTML <version>" boxes. 1030 // Remove the "Introduced in HTML <version>" boxes.
1005 for (Element e in document.queryAll('.htmlVersionHeaderTemplate')) { 1031 for (Element e in document.queryAll('.htmlVersionHeaderTemplate')) {
1006 e.remove(); 1032 e.remove();
1007 } 1033 }
1008 1034
1009 // Flatten the list of known DOM types into a faster and case-insensitive map. 1035 // Flatten the list of known DOM types into a faster and case-insensitive
1036 // map.
1010 domTypes = {}; 1037 domTypes = {};
1011 for (final domType in domTypesRaw) { 1038 for (final domType in domTypesRaw) {
1012 domTypes[domType.toLowerCase()] = domType; 1039 domTypes[domType.toLowerCase()] = domType;
1013 } 1040 }
1014 1041
1015 // Fix up links. 1042 // Fix up links.
1016 final SHORT_LINK = const RegExp(@'^[\w/]+$'); 1043 final SHORT_LINK = const RegExp(@'^[\w/]+$');
1017 final INNER_LINK = const RegExp(@'[Ee]n/(?:[\w/]+/|)([\w#.]+)(?:\(\))?$'); 1044 final INNER_LINK = const RegExp(@'[Ee]n/(?:[\w/]+/|)([\w#.]+)(?:\(\))?$');
1018 final MEMBER_LINK = const RegExp(@'(\w+)[.#](\w+)'); 1045 final MEMBER_LINK = const RegExp(@'(\w+)[.#](\w+)');
1019 final RELATIVE_LINK = const RegExp(@'^(?:../)*/?[Ee][Nn]/(.+)'); 1046 final RELATIVE_LINK = const RegExp(@'^(?:../)*/?[Ee][Nn]/(.+)');
1020 1047
1021 // - Make relative links absolute. 1048 // - Make relative links absolute.
1022 // - If we can, take links that point to other MDN pages and retarget them 1049 // - If we can, take links that point to other MDN pages and retarget them
1023 // to appropriate pages in our docs. 1050 // to appropriate pages in our docs.
1024 // TODO(rnystrom): Add rel external to links we didn't fix. 1051 // TODO(rnystrom): Add rel external to links we didn't fix.
1025 for (AnchorElement a in document.queryAll('a')) { 1052 for (AnchorElement a in document.queryAll('a')) {
1026 // Get the raw attribute because we *don't* want the browser to fully- 1053 // Get the raw attribute because we *don't* want the browser to fully-
1027 // qualify the name for us since it has the wrong base address for the page. 1054 // qualify the name for us since it has the wrong base address for the
1055 // page.
1028 var href = a.attributes['href']; 1056 var href = a.attributes['href'];
1029 1057
1030 // Ignore busted links. 1058 // Ignore busted links.
1031 if (href == null) continue; 1059 if (href == null) continue;
1032 1060
1033 // If we can recognize what it's pointing to, point it to our page instead. 1061 // If we can recognize what it's pointing to, point it to our page instead.
1034 tryToLinkToRealType(maybeType) { 1062 tryToLinkToRealType(maybeType) {
1035 // See if we know a type with that name. 1063 // See if we know a type with that name.
1036 final realType = domTypes[maybeType.toLowerCase()]; 1064 final realType = domTypes[maybeType.toLowerCase()];
1037 if (realType != null) { 1065 if (realType != null) {
(...skipping 25 matching lines...) Expand all
1063 tryToLinkToRealType(member[1]); 1091 tryToLinkToRealType(member[1]);
1064 } else { 1092 } else {
1065 tryToLinkToRealType(match[1]); 1093 tryToLinkToRealType(match[1]);
1066 } 1094 }
1067 } 1095 }
1068 1096
1069 // Put it back into the element. 1097 // Put it back into the element.
1070 a.attributes['href'] = href; 1098 a.attributes['href'] = href;
1071 } 1099 }
1072 1100
1073 if (title.toLowerCase().indexOf(currentTypeTiny.toLowerCase()) == -1) { 1101 if (!title.toLowerCase().contains(currentTypeTiny.toLowerCase())) {
1074 bool foundMatch = false; 1102 bool foundMatch = false;
1075 // Test out if the title is really an HTML tag that matches the 1103 // Test out if the title is really an HTML tag that matches the
1076 // current class name. 1104 // current class name.
1077 for (String tag in [title.split(" ")[0], title.split(".").last()]) { 1105 for (String tag in [title.split(" ")[0], title.split(".").last()]) {
1078 try { 1106 try {
1079 dom.Element element = dom.document.createElement(tag); 1107 dom.Element element = dom.document.createElement(tag);
1080 if (element.typeName == currentType) { 1108 if (element.typeName == currentType) {
1081 foundMatch = true; 1109 foundMatch = true;
1082 break; 1110 break;
1083 } 1111 }
1084 } catch(e) {} 1112 } catch(e) {}
1085 } 1113 }
1086 if (foundMatch == false) { 1114 if (!foundMatch) {
1087 dbEntry['skipped'] = true; 1115 dbEntry['skipped'] = true;
1088 dbEntry['cause'] = "Suspect title"; 1116 dbEntry['cause'] = "Suspect title";
1089 onEnd(); 1117 onEnd();
1090 return; 1118 return;
1091 } 1119 }
1092 } 1120 }
1093 1121
1094 Element root = document.query(".pageText"); 1122 Element root = document.query(".pageText");
1095 if (root == null) { 1123 if (root == null) {
1096 dbEntry['cause'] = '.pageText not found'; 1124 dbEntry['cause'] = '.pageText not found';
1097 onEnd(); 1125 onEnd();
1098 return; 1126 return;
1099 } 1127 }
1100 1128
1101 markRemoved(root.query("#Notes")); 1129 markRemoved(root.query("#Notes"));
1102 List members = dbEntry['members']; 1130 List members = dbEntry['members'];
1103 1131
1104 markRemoved(document.queryAll(".pageToc, footer, header, #nav-toolbar")); 1132 markRemoved(document.queryAll(".pageToc, footer, header, #nav-toolbar"));
1105 markRemoved(document.queryAll("#article-nav")); 1133 markRemoved(document.queryAll("#article-nav"));
1106 markRemoved(document.queryAll(".hideforedit")); 1134 markRemoved(document.queryAll(".hideforedit"));
1107 markRemoved(document.queryAll(".navbox")); 1135 markRemoved(document.queryAll(".navbox"));
1108 markRemoved(document.query("#Method_overview")); 1136 markRemoved(document.query("#Method_overview"));
1109 markRemoved(document.queryAll("h1, h2")); 1137 markRemoved(document.queryAll("h1, h2"));
1110 1138
1111 scrapeSection(root, "#Methods", currentType, members, 'methods'); 1139 scrapeSection(root, "#Methods", currentType, members, 'methods');
1112 scrapeSection(root, "#Constants, #Error_codes, #State_constants", currentType, members, 'constants'); 1140 scrapeSection(root, "#Constants, #Error_codes, #State_constants",
1141 currentType, members, 'constants');
1113 // TODO(jacobr): infer tables based on multiple matches rather than 1142 // TODO(jacobr): infer tables based on multiple matches rather than
1114 // using a hard coded list of section ids. 1143 // using a hard coded list of section ids.
1115 scrapeSection(root, 1144 scrapeSection(root,
1116 "[id^=Properties], #Notes, [id^=Other_properties], #Attributes, #DOM_prope rties, #Event_handlers, #Event_Handlers", 1145 "[id^=Properties], #Notes, [id^=Other_properties], #Attributes, " +
1146 "#DOM_properties, #Event_handlers, #Event_Handlers",
1117 currentType, members, 'properties'); 1147 currentType, members, 'properties');
1118 1148
1119 // Avoid doing this till now to avoid messing up the section scrape. 1149 // Avoid doing this till now to avoid messing up the section scrape.
1120 markRemoved(document.queryAll("h3")); 1150 markRemoved(document.queryAll("h3"));
1121 1151
1122 ElementList $examples = root.queryAll("span[id^=example], span[id^=Example]"); 1152 ElementList examples = root.queryAll("span[id^=example], span[id^=Example]");
1123 1153
1124 extractSection("#See_also", 'seeAlso'); 1154 extractSection("#See_also", 'seeAlso');
1125 extractSection("#Specification, #Specifications", "specification"); 1155 extractSection("#Specification, #Specifications", "specification");
1126 // $("#Methods").parent().remove(); // not safe (e.g. Document)
1127 1156
1128 // TODO(jacobr): actually extract the constructor(s) 1157 // TODO(jacobr): actually extract the constructor(s)
1129 extractSection("#Constructor, #Constructors", 'constructor'); 1158 extractSection("#Constructor, #Constructors", 'constructor');
1130 extractSection("#Browser_compatibility, #Compatibility", 'compatibility'); 1159 extractSection("#Browser_compatibility, #Compatibility", 'compatibility');
1131 1160
1132 List<String> exampleHtml = []; 1161 List<String> exampleHtml = [];
1133 for (Element e in $examples) { 1162 for (Element e in examples) {
1134 e.classes.add(DART_REMOVED); 1163 e.classes.add(DART_REMOVED);
1135 } 1164 }
1136 for (Element e in $examples) { 1165 for (Element e in examples) {
1137 String html = filteredHtml(e, root, null, 1166 String html = filteredHtml(e, root, null,
1138 (DocumentFragment fragment) { 1167 (DocumentFragment fragment) {
1139 removeHeaders(fragment); 1168 removeHeaders(fragment);
1140 if (fragment.text.trim().toLowerCase() == "example") { 1169 if (fragment.text.trim().toLowerCase() == "example") {
1141 // Degenerate example. 1170 // Degenerate example.
1142 fragment.nodes.clear(); 1171 fragment.nodes.clear();
1143 } 1172 }
1144 }).html; 1173 }).html;
1145 if (html.length > 0) { 1174 if (html.length > 0) {
1146 exampleHtml.add(html); 1175 exampleHtml.add(html);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 } 1211 }
1183 1212
1184 void main() { 1213 void main() {
1185 window.on.load.add(documentLoaded); 1214 window.on.load.add(documentLoaded);
1186 } 1215 }
1187 1216
1188 void documentLoaded(event) { 1217 void documentLoaded(event) {
1189 new XMLHttpRequest.getTEMPNAME('${window.location}.json', (req) { 1218 new XMLHttpRequest.getTEMPNAME('${window.location}.json', (req) {
1190 data = JSON.parse(req.responseText); 1219 data = JSON.parse(req.responseText);
1191 dbEntry = {'members': [], 'srcUrl': pageUrl}; 1220 dbEntry = {'members': [], 'srcUrl': pageUrl};
1192 resourceLoaded(); 1221 run();
1193 }); 1222 });
1194 } 1223 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698