r102408 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102407‎ | r102408 | r102409 >
Date:16:08, 8 November 2011
Author:gwicke
Status:deferred
Tags:
Comment:
Extract text from inline elements for better testing. Slightly improved
handling of comment-only lines. Change pre to leaf content model.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/serializers/es.HtmlSerializer.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/pegParser.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/pegParser.pegjs.txt
@@ -84,7 +84,39 @@
8585 }
8686 }
8787 return bTypes;
88 - }
 88+ };
 89+
 90+ var extractInline = function ( node ) {
 91+ return { text: extractText(node)
 92+ }
 93+ };
 94+
 95+
 96+ var extractText = function ( node ) {
 97+ dp("extract: " + print_r(node));
 98+ if (typeof node === 'string') {
 99+ return node;
 100+ } else if ($.isArray(node)) {
 101+ var texts = [];
 102+ for (var i = 0, length = node.length; i < length; i++) {
 103+ texts.push(extractText(node[i]));
 104+ }
 105+ return texts.join('');
 106+ } else if ( 'text' in node ) {
 107+ return extractText(node.text);
 108+ } else if ( 'content' in node ) {
 109+ return extractText(node.content);
 110+ } else if ( 'children' in node ) {
 111+ var texts = [];
 112+ for (var i = 0, length = node.children.length; i < length; i++) {
 113+ texts.push(extractText(node.children[i]));
 114+ }
 115+ return texts.join('');
 116+ } else {
 117+ console.log("extract failed!" + print_r(node));
 118+ throw ("extract failed: " + print_r(node));
 119+ }
 120+ };
89121 }
90122
91123 start
@@ -116,8 +148,12 @@
117149
118150
119151 // Start of line
120 -sol = (newline / & { return pos === 0; } { return true; }) (comment newline?)?
 152+sol = (newline / & { return pos === 0; } { return true; })
 153+ cn:(comment n:newline? { return n })? {
 154+ return cn;
 155+ }
121156
 157+
122158 newline
123159 = '\n' / '\r\n'
124160
@@ -146,7 +182,7 @@
147183 return {
148184 type: 'heading',
149185 attributes: {level: 1},
150 - text: c
 186+ content: extractInline(c)
151187 }
152188 }
153189 / { clearFlag('h'); clearFlag('h1'); return null }
@@ -161,7 +197,7 @@
162198 return {
163199 type: 'heading',
164200 attributes: {level: 2},
165 - content: c
 201+ content: extractInline(c)
166202 }
167203 }
168204 / { clearFlag('h'); clearFlag('h2'); return null }
@@ -176,7 +212,7 @@
177213 return {
178214 type: 'heading',
179215 attributes: {level: 3},
180 - content: c
 216+ content: extractInline(c)
181217 }
182218 }
183219 / { clearFlag('h'); clearFlag('h3'); return null }
@@ -191,7 +227,7 @@
192228 return {
193229 type: 'heading',
194230 attributes: {level: 4},
195 - content: c
 231+ content: extractInline(c)
196232 }
197233 }
198234 / { clearFlag('h'); clearFlag('h4'); return null }
@@ -205,7 +241,7 @@
206242 return {
207243 type: 'heading',
208244 attributes: {level: 5},
209 - content: c
 245+ content: extractInline(c)
210246 }
211247 }
212248 / { clearFlag('h'); clearFlag('h5'); return null }
@@ -219,7 +255,7 @@
220256 return {
221257 type: 'heading',
222258 attributes: {level: 6},
223 - content: c
 259+ content: extractInline(c)
224260 }
225261 }
226262 / { clearFlag('h'); clearFlag('h6'); return null }
@@ -237,10 +273,10 @@
238274 = (sol br)? para_lines
239275
240276 para_lines
241 - = sol c:inlineline cs:(!block_lines para_lines)* {
 277+ = s:sol c:inlineline cs:(!block_lines para_lines)* {
242278 return {
243279 type: 'paragraph',
244 - content: c[0] // XXX Hack alarm!
 280+ content: extractInline([s].concat([c]).concat(cs))
245281 }
246282 }
247283
@@ -250,7 +286,7 @@
251287 = l:pre_indent_line+ {
252288 return {
253289 type: 'pre',
254 - children: l
 290+ content: extractInline(l)
255291 }
256292 }
257293 pre_indent_line = sol space l:inlineline { return l }
@@ -305,7 +341,7 @@
306342 = c:(text / !inline_breaks (inline_element / [^\n]))+ {
307343 var out = [];
308344 var text = '';
309 - dp("inlineline: " + print_r(c));
 345+ //dp("inlineline: " + print_r(c));
310346 for (var i = 0; i < c.length; i++) {
311347 if (typeof c[i] == 'string') {
312348 text += c[i];
@@ -458,7 +494,7 @@
459495 clearFlag('bold');
460496 return {
461497 type: 'b',
462 - text: c,
 498+ content: {text: c}
463499 }
464500 }
465501 / bold_marker { clearFlag('bold'); return null }
@@ -476,7 +512,7 @@
477513 dp('ileave:' + pos);
478514 return {
479515 type: 'i',
480 - text: c
 516+ content: {text: c}
481517 }
482518 }
483519 / italic_marker { clearFlag('italic'); return null }
@@ -623,7 +659,7 @@
624660 attributes: {
625661 styles: bulletsToTypes(bullets)
626662 },
627 - content: c[0]
 663+ content: extractInline(c)
628664 };
629665 }
630666
@@ -642,12 +678,12 @@
643679 {
644680 type: 'listItem',
645681 attributes: {styles: bulletsToTypes(bullets)},
646 - content: {text: c.join('')}
 682+ content: extractInline(c)
647683 }, {
648684 type: 'listItem',
649685 attributes: {styles: bulletsToTypes(
650686 bullets.slice(0, bullets.length - 1) + ':')},
651 - content: {text: d.join('')}
 687+ content: extractInline(d)
652688 }
653689 ]
654690 }
Index: trunk/extensions/VisualEditor/modules/es/serializers/es.HtmlSerializer.js
@@ -62,7 +62,7 @@
6363
6464 es.HtmlSerializer.prototype.pre = function( node ) {
6565 return es.Html.makeTag(
66 - 'pre', {}, this.document( node, true )
 66+ 'pre', {}, this.content( node.content, true )
6767 );
6868 };
6969

Status & tagging log