r105431 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105430‎ | r105431 | r105432 >
Date:14:46, 7 December 2011
Author:gwicke
Status:deferred
Tags:
Comment:
Process template arguments into an object.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/pegParser.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/pegParser.pegjs.txt
@@ -475,12 +475,14 @@
476476 // return res
477477 // }
478478
479 -htmlentity = "&" c:[#0-9a-zA-Z]+ ";" { return unentity("&" + c.join('') + ";") }
 479+htmlentity = "&" c:[#0-9a-zA-Z]+ ";" {
 480+ return unentity("&" + c.join('') + ";")
 481+}
480482
481483 space
482484 = s:[ \t]+ { return s.join(''); }
483485
484 -spaceTokenList
 486+optionalSpaceToken
485487 = s:space* {
486488 if ( s.length ) {
487489 return [{type: 'TEXT', value: s.join('')}];
@@ -551,8 +553,8 @@
552554 / table
553555 / lists
554556 // tag-only lines should not trigger pre
555 - / st:spaceTokenList
556 - bt:(bts:block_tag stl:spaceTokenList { return bts.concat(stl) })+
 557+ / st:optionalSpaceToken
 558+ bt:(bts:block_tag stl:optionalSpaceToken { return bts.concat(stl) })+
557559 &eolf {
558560 return st.concat(bt);
559561 }
@@ -774,9 +776,23 @@
775777
776778 template
777779 = "{{" target:template_target params:("|" p:template_param { return p })* "}}" {
778 - var obj = { type: 'TAG', name: 'template', attribs: [['target', target]] }
 780+ var obj = { type: 'TAG', name: 'template',
 781+ attribs: [['target', target]],
 782+ args: {}}
779783 if (params && params.length) {
780 - obj.attribs = obj.attribs.concat(params);
 784+ var position = 1;
 785+ for ( var i = 0, l = params.length; i < l; i++ ) {
 786+ var param = params[i];
 787+ if ( param[0] === null ) {
 788+ obj.args[position] = param[1];
 789+ position++;
 790+ } else {
 791+ obj.args[param[0]] = param[1];
 792+ }
 793+ }
 794+ // HACK: temporarily also push the args into an attribute
 795+ // (just for debugging)
 796+ obj.attribs.push(['data-args', JSON.stringify(obj.args)]);
781797 }
782798 // Should actually use a self-closing tag here, but the Node HTML5
783799 // parser only recognizes known self-closing tags for now, so use an
@@ -792,20 +808,20 @@
793809 * (to json) before passing remaining args to the tree builder */
794810 template_param
795811 = name:template_param_name "=" c:template_param_text {
796 - return ['data-k-' + name, c];
 812+ return [name, c];
797813 } / c:template_param_text {
798 - return ['data-p-', c];
 814+ return [null, c];
799815 }
800816
801817 tplarg
802 - = "{{{" name:link_target params:("|" p:template_param { return p })* "}}}" {
 818+ = "{{{" name:link_target params:("|" ! "}}}" p:template_param { return p })* "}}}" {
803819 var obj = {
804820 type: 'SELFCLOSINGTAG',
805821 name: 'templatearg',
806822 attribs: [['argname', name]]
807823 };
808824 if (params && params.length) {
809 - obj.attribs = obj.attribs.concat(params);
 825+ obj.attribs.push(['data-args', JSON.stringify(params)]);
810826 }
811827 return obj;
812828 }
@@ -818,6 +834,7 @@
819835 //= h:( !"}}" x:([^|]) { return x } )* { return h.join(''); }
820836
821837
 838+// XXX: convert to inlineline with syntactic stop on "}}"
822839 template_param_text_chunk
823840 = comment
824841 / xmlish_tag

Status & tagging log