Index: trunk/extensions/ParserPlayground/modules/ext.parserPlayground.renderer.js |
— | — | @@ -128,10 +128,10 @@ |
129 | 129 | case 'dd': |
130 | 130 | case 'li': |
131 | 131 | case 'table': |
132 | | - case 'table_row': |
133 | | - case 'table_caption': |
134 | | - case 'table_data': |
135 | | - case 'table_header': |
| 132 | + case 'tableRow': |
| 133 | + case 'tableCaption': |
| 134 | + case 'tableCell': |
| 135 | + case 'tableHeader': |
136 | 136 | var $span = $('<' + tree.type + '>'); |
137 | 137 | if ('attrs' in tree) { |
138 | 138 | $.map(tree.attrs, function(val, key) { |
Index: trunk/extensions/ParserPlayground/modules/pegParser.pegjs.txt |
— | — | @@ -539,26 +539,30 @@ |
540 | 540 | /* Tables */ |
541 | 541 | |
542 | 542 | table |
543 | | - = table_start c:table_caption? b:table_body? table_end { |
544 | | - var res = null; |
| 543 | + = tas:table_start c:table_caption? b:table_body? table_end { |
| 544 | + var res = {type: 'table'} |
545 | 545 | var body = b !== '' ? b : []; |
546 | 546 | if (c !== '') { |
547 | | - res = {type: 'table', content: [c].concat(body)}; |
| 547 | + res.content = [c].concat(body); |
548 | 548 | } else { |
549 | | - res = {type: 'table', content: body }; |
| 549 | + res.content = body; |
550 | 550 | } |
551 | | - //console.log(print_r(res)); |
| 551 | + if (tas.length > 0) { |
| 552 | + // FIXME: actually parse and build structure |
| 553 | + res.attributes = { unparsed: tas } |
| 554 | + } |
| 555 | + console.log(print_r(res)); |
552 | 556 | return res; |
553 | 557 | } |
554 | 558 | |
555 | | -table_start = "{|" table_attribs* space* newline? |
| 559 | +table_start = "{|" ta:table_attribs* space* newline? { return ta } |
556 | 560 | |
557 | 561 | table_attribs = anything |
558 | 562 | |
559 | 563 | table_caption |
560 | 564 | = "|+" c:(inline_element / anything / [^\n])* newline? { |
561 | 565 | return { |
562 | | - type: 'table_caption', |
| 566 | + type: 'tableCaption', |
563 | 567 | content: c |
564 | 568 | } |
565 | 569 | } |
— | — | @@ -577,7 +581,7 @@ |
578 | 582 | table_firstrow |
579 | 583 | = td:table_data+ { |
580 | 584 | return { |
581 | | - type: 'table_row', |
| 585 | + type: 'tableRow', |
582 | 586 | content: td |
583 | 587 | }; |
584 | 588 | } |
— | — | @@ -585,28 +589,33 @@ |
586 | 590 | table_row |
587 | 591 | = "|-" space* newline? td:(table_data / table_header)* { |
588 | 592 | return { |
589 | | - type: 'table_row', |
| 593 | + type: 'tableRow', |
590 | 594 | content: td |
591 | 595 | }; |
592 | 596 | } |
593 | 597 | |
| 598 | +/* TODO: Allow general block-level or inline elements, except if they span a |
| 599 | + * source line starting with a pipe. To avoid duplicating all block-level |
| 600 | + * productions, a quick check if a potential block-level match spanned a line |
| 601 | + * starting with a pipe might be used. Checking this requires access to the |
| 602 | + * matched source string. */ |
594 | 603 | table_data |
595 | 604 | = t:table { |
596 | | - console.log("recursive table result:" + print_r(t)); |
| 605 | + //console.log("recursive table result:" + print_r(t)); |
597 | 606 | return { |
598 | | - type: 'table_data', |
| 607 | + type: 'tableCell', |
599 | 608 | content: [t] |
600 | 609 | } |
601 | 610 | } |
602 | 611 | / "||" td_attr? td:[^|]* newline? { |
603 | 612 | return { |
604 | | - type: 'table_data', |
| 613 | + type: 'tableCell', |
605 | 614 | content: td.join('') |
606 | 615 | }; |
607 | 616 | } |
608 | 617 | / "|" ![}+-] td_attr? td:[^|\n]* newline? { |
609 | 618 | return { |
610 | | - type: 'table_data', |
| 619 | + type: 'tableCell', |
611 | 620 | content: td.join('') |
612 | 621 | }; |
613 | 622 | } |
— | — | @@ -616,15 +625,22 @@ |
617 | 626 | table_header |
618 | 627 | = "!!" c:(block/ inline_element / text / ("!" !"!") / [^!\n])* newline? { |
619 | 628 | return { |
620 | | - type: 'table_header', |
| 629 | + type: 'tableHeader', |
621 | 630 | content: c |
622 | 631 | } |
623 | 632 | } |
624 | 633 | / "!" c:(block/ inline_element / text / '!' !'!' / [^!\n])* newline? { |
625 | 634 | return { |
626 | | - type: 'table_header', |
| 635 | + type: 'tableHeader', |
627 | 636 | content: c |
628 | 637 | } |
629 | 638 | } |
630 | 639 | |
631 | 640 | table_end = "|}" newline? |
| 641 | + |
| 642 | + |
| 643 | +/* Wikidom TODO: |
| 644 | + * split off text into content nodes |
| 645 | + * convert inlines into annotations |
| 646 | + * change contents into children |
| 647 | + */ |