Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js |
— | — | @@ -203,7 +203,7 @@ |
204 | 204 | |
205 | 205 | // Build a DOM tree from tokens using the HTML tree builder/parser. |
206 | 206 | pt.buildTree( tokens, treeBuilder ); |
207 | | - |
| 207 | + |
208 | 208 | // Perform post-processing on DOM. |
209 | 209 | pt.postProcessor.doPostProcess(treeBuilder.document); |
210 | 210 | |
— | — | @@ -447,9 +447,8 @@ |
448 | 448 | //}); |
449 | 449 | //var res = es.HtmlSerializer.stringify(tokens,environment); |
450 | 450 | |
451 | | - //console.log(JSON.stringify(tokens)); |
452 | 451 | //Slightly better token output debugging: |
453 | | - //console.log( util.inspect( tokens, false, null ).yellow); |
| 452 | + //console.log( util.inspect( res.tokens, false, null ).yellow); |
454 | 453 | |
455 | 454 | // Transform tokens using the TokenTransformDispatcher. When done, the |
456 | 455 | // TokenTransformDispatcher calls buildTree() and checkResult() with the |
— | — | @@ -457,6 +456,9 @@ |
458 | 457 | |
459 | 458 | // Append the end |
460 | 459 | res.tokens.push({type: 'END'}); |
| 460 | + |
| 461 | + //console.log(JSON.stringify(res.tokens, null, 2)); |
| 462 | + |
461 | 463 | this.tokenDispatcher.transformTokens( res.tokens ); |
462 | 464 | } |
463 | 465 | }; |
— | — | @@ -554,6 +556,12 @@ |
555 | 557 | for (var i = 0, length = tokens.length; i < length; i++) { |
556 | 558 | treeBuilder.processToken(tokens[i]); |
557 | 559 | } |
| 560 | + |
| 561 | + // FIXME HACK: For some reason the end token is not processed sometimes, |
| 562 | + // which normally fixes the body reference up. |
| 563 | + treeBuilder.document.body = treeBuilder.parser |
| 564 | + .document.getElementsByTagName('body')[0]; |
| 565 | + |
558 | 566 | }; |
559 | 567 | |
560 | 568 | /** |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.HTML5TreeBuilder.node.js |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | // html tree builder by emitting the token. |
27 | 27 | FauxHTML5.TreeBuilder.prototype.processToken = function (token) { |
28 | 28 | var att = function (maybeAttribs) { |
29 | | - if ( $.isArray(maybeAttribs) ) { |
| 29 | + if ( $.isArray( maybeAttribs ) ) { |
30 | 30 | var atts = []; |
31 | 31 | for(var i = 0, length = maybeAttribs.length; i < length; i++) { |
32 | 32 | var att = maybeAttribs[i]; |
— | — | @@ -62,12 +62,16 @@ |
63 | 63 | break; |
64 | 64 | case "END": |
65 | 65 | this.emit('end'); |
| 66 | + console.log("at end.."); |
66 | 67 | this.document = this.parser.document; |
67 | | - // HACK: This should not be needed really. |
68 | | - this.document.body = this.document.getElementsByTagName('body')[0]; |
| 68 | + if ( ! this.document.body ) { |
| 69 | + // HACK: This should not be needed really. |
| 70 | + this.document.body = this.parser.document.getElementsByTagName('body')[0]; |
| 71 | + } |
69 | 72 | break; |
70 | 73 | case "NEWLINE": |
71 | 74 | //this.emit('end'); |
| 75 | + this.emit('token', {type: 'Characters', data: "\n"}); |
72 | 76 | break; |
73 | 77 | default: |
74 | 78 | console.log("Unhandled token: " + JSON.stringify(token)); |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.DOMConverter.js |
— | — | @@ -395,8 +395,11 @@ |
396 | 396 | var attrib = attribs.item(i), |
397 | 397 | key = attrib.name; |
398 | 398 | console.log('key: ' + key); |
399 | | - if ( key.match( /^data-/ ) ) { |
| 399 | + if ( key.match( /^data-json-/ ) ) { |
400 | 400 | // strip data- prefix from data-* |
| 401 | + out[key.replace( /^data-json-/, '' )] = JSON.parse(attrib.value); |
| 402 | + } else if ( key.match( /^data-/ ) ) { |
| 403 | + // strip data- prefix from data-* |
401 | 404 | out[key.replace( /^data-/, '' )] = attrib.value; |
402 | 405 | } else { |
403 | 406 | // prefix html properties with html/ |
— | — | @@ -412,8 +415,11 @@ |
413 | 416 | for ( var i = 0, l = attribs.length; i < l; i++ ) { |
414 | 417 | var attrib = attribs.item(i), |
415 | 418 | key = attrib.name; |
416 | | - if ( key.match( /^data-/ ) ) { |
| 419 | + if ( key.match( /^data-json-/ ) ) { |
417 | 420 | // strip data- prefix from data-* |
| 421 | + out[key.replace( /^data-json-/, '' )] = JSON.parse(attrib.value); |
| 422 | + } else if ( key.match( /^data-/ ) ) { |
| 423 | + // strip data- prefix from data-* |
418 | 424 | out[key.replace( /^data-/, '' )] = attrib.value; |
419 | 425 | } else { |
420 | 426 | // pass through a few whitelisted keys |
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt |
— | — | @@ -644,7 +644,7 @@ |
645 | 645 | params:(newline? "|" newline? p:template_param { return p })* |
646 | 646 | "}}" { |
647 | 647 | var obj = { type: 'TAG', name: 'template', |
648 | | - attribs: [['target', target]], |
| 648 | + attribs: [['data-target', target]], |
649 | 649 | args: {}} |
650 | 650 | if (params && params.length) { |
651 | 651 | var position = 1; |
— | — | @@ -659,7 +659,7 @@ |
660 | 660 | } |
661 | 661 | // HACK: temporarily also push the args into an attribute |
662 | 662 | // (just for debugging) |
663 | | - obj.attribs.push(['data-args', JSON.stringify(obj.args)]); |
| 663 | + obj.attribs.push(['data-json-args', JSON.stringify(obj.args)]); |
664 | 664 | } |
665 | 665 | // Should actually use a self-closing tag here, but the Node HTML5 |
666 | 666 | // parser only recognizes known self-closing tags for now, so use an |
— | — | @@ -687,7 +687,7 @@ |
688 | 688 | }; |
689 | 689 | if (params && params.length) { |
690 | 690 | // HACK, not final. |
691 | | - obj.attribs.push(['data-args', JSON.stringify(params)]); |
| 691 | + obj.attribs.push(['data-json-args', JSON.stringify(params)]); |
692 | 692 | } |
693 | 693 | return obj; |
694 | 694 | } |