r105211 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105210‎ | r105211 | r105212 >
Date:20:03, 5 December 2011
Author:gwicke
Status:deferred
Tags:
Comment:
Recognize block-level elements independent of case; Ignore toc and section
edit links in tests. 148 parser tests passing.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/pegParser.pegjs.txt (modified) (history)
  • /trunk/extensions/VisualEditor/tests/parser/parserTests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js
@@ -307,6 +307,10 @@
308308 .replace(/(title|class|rel)="[^"]+"/g, '')
309309 // strip red link markup, we do not check if a page exists yet
310310 .replace(/\/index.php\?title=|&action=edit&redlink=1/g, '')
 311+ // do not expect a toc for now
 312+ .replace(/<table id="toc>.*?<\/table>/g, '')
 313+ // do not expect section editing for now
 314+ .replace(/<h[1-6]> <span>[.*?<\/span><span.*?]<\/span>/g, '')
311315 // the expected html has some extra space in tags, strip it
312316 .replace(/<a +href/g, '<a href')
313317 .replace(/" +>/g, '">');
Index: trunk/extensions/VisualEditor/modules/parser/pegParser.pegjs.txt
@@ -356,7 +356,25 @@
357357 // text start position
358358 var textStart = 0;
359359
 360+ // hack to support numbered external links ([http://example.com]).
 361+ // XXX: Move to token stream transform after templates are expanded!
360362 var linkCount = 1;
 363+
 364+ // Define block-level tags in JS, so we can use toLowerCase to match tags
 365+ // case-independently. This would be quite ugly (and possibly slower) if
 366+ // done manually in the grammar.
 367+ var block_names = (function () {
 368+ var names = [ "p", "table", "td", "tr", "ul", "ol"
 369+ , "li", "dl", "dt", "dd", "div", "center"
 370+ , "blockquote" ];
 371+ var bnames = {};
 372+ for(var i = 0, l = names.length; i < l; i++) {
 373+ bnames[names[i]] = true;
 374+ }
 375+ return bnames;
 376+ })();
 377+
 378+
361379 }
362380
363381 start
@@ -920,10 +938,14 @@
921939 // See http://dev.w3.org/html5/spec/Overview.html#syntax-tag-name and
922940 // following paragraphs
923941 block_tag
924 - = "<" end:"/"? name:block_name
 942+ = "<" end:"/"? name:(cs:[a-zA-Z]+ { return cs.join('') })
925943 attribs:generic_attribute*
926944 selfclose:"/"?
927945 ">" {
 946+ if (block_names[name.toLowerCase()] !== true) {
 947+ // abort match if tag is not block-level
 948+ return null;
 949+ }
928950 var res = {name: name, attribs: attribs};
929951 if ( end != '' ) {
930952 res.type = 'ENDTAG';
@@ -935,12 +957,7 @@
936958 return res;
937959 }
938960
939 -block_name
940 - = "p" / "table" / "td" / "tr" / "ul" / "ol"
941 - / "li" / "dl" / "dt" / "dd" / "div" / "center"
942 - / "blockquote"
943961
944 -
945962 // See http://dev.w3.org/html5/spec/Overview.html#syntax-tag-name and
946963 // following paragraphs
947964 generic_tag
@@ -1101,9 +1118,11 @@
11021119 }
11031120
11041121 li = bullets:list_char+
1105 - c:inlineline
 1122+ c:inlineline?
11061123 &eolf
11071124 {
 1125+ if ( c == '' )
 1126+ c = [];
11081127 return [ { type: 'TAG',
11091128 name: 'listItem',
11101129 bullets: bullets }

Status & tagging log