r109173 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109172‎ | r109173 | r109174 >
Date:18:30, 17 January 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Use isBlockTag in DOMPostProcessor
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.Util.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.PostExpandParagraphHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.DOMPostProcessor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/ext.Util.js
@@ -14,42 +14,54 @@
1515 * @param {Object} token: The token to check
1616 * @returns {Boolean}: True if token is block-level, false otherwise.
1717 */
18 -Util.prototype.isBlock = function ( token ) {
 18+Util.prototype.isBlockToken = function ( token ) {
1919 if ( token.type === 'TAG' ||
2020 token.type === 'ENDTAG' ||
2121 token.type === 'SELFCLOSINGTAG' ) {
22 - switch (token.name.toLowerCase()) {
23 - case 'div':
24 - case 'table':
25 - case 'td':
26 - case 'tr':
27 - case 'tbody':
28 - case 'p':
29 - case 'ul':
30 - case 'ol':
31 - case 'li':
32 - case 'dl':
33 - case 'dt':
34 - case 'dd':
35 - case 'img': // hmm!
36 - case 'pre':
37 - case 'center':
38 - case 'blockquote':
39 - case 'h1':
40 - case 'h2':
41 - case 'h3':
42 - case 'h4':
43 - case 'h5':
44 - case 'h6':
45 - return true;
46 - default:
47 - return false;
48 - }
 22+ return this.isBlockTag( token.name.toLowerCase() );
4923 } else {
5024 return false;
5125 }
5226 };
5327
 28+/**
 29+ * Determine if a tag name is block-level or not
 30+ *
 31+ * @static
 32+ * @method
 33+ * @param {String} name: Lower-case tag name
 34+ * @returns {Boolean}: True if tag is block-level, false otherwise.
 35+ */
 36+Util.prototype.isBlockTag = function ( name ) {
 37+ switch ( name ) {
 38+ case 'div':
 39+ case 'table':
 40+ case 'td':
 41+ case 'tr':
 42+ case 'tbody':
 43+ case 'p':
 44+ case 'ul':
 45+ case 'ol':
 46+ case 'li':
 47+ case 'dl':
 48+ case 'dt':
 49+ case 'dd':
 50+ case 'img': // hmm!
 51+ case 'pre':
 52+ case 'center':
 53+ case 'blockquote':
 54+ case 'h1':
 55+ case 'h2':
 56+ case 'h3':
 57+ case 'h4':
 58+ case 'h5':
 59+ case 'h6':
 60+ return true;
 61+ default:
 62+ return false;
 63+ }
 64+};
 65+
5466 if (typeof module == "object") {
5567 module.exports.Util = Util;
5668 }
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.DOMPostProcessor.js
@@ -1,37 +1,9 @@
22 /* Perform post-processing steps on an already-built HTML DOM. */
33
4 -var events = require('events');
 4+var events = require('events'),
 5+ util = require('./ext.Util.js'),
 6+ Util = new util.Util();
57
6 -var isBlock = function isBlock (name) {
7 - switch (name.toLowerCase()) {
8 - case 'div':
9 - case 'table':
10 - case 'td':
11 - case 'tr':
12 - case 'tbody':
13 - case 'p':
14 - case 'ul':
15 - case 'ol':
16 - case 'li':
17 - case 'dl':
18 - case 'dt':
19 - case 'dd':
20 - case 'img': // hmm!
21 - case 'pre':
22 - case 'center':
23 - case 'blockquote':
24 - case 'h1':
25 - case 'h2':
26 - case 'h3':
27 - case 'h4':
28 - case 'h5':
29 - case 'h6':
30 - return true;
31 - default:
32 - return false;
33 - }
34 -};
35 -
368 // Quick HACK: define Node constants
379 // https://developer.mozilla.org/en/nodeType
3810 var Node = {
@@ -61,7 +33,7 @@
6234 (ctype === Node.COMMENT_NODE && inParagraph ) ||
6335 (ctype !== Node.TEXT_NODE &&
6436 ctype !== Node.COMMENT_NODE &&
65 - !isBlock(child.nodeName))
 37+ !Util.isBlockTag(child.nodeName.toLowerCase()))
6638 )
6739 {
6840 // wrap in paragraph
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.PostExpandParagraphHandler.js
@@ -84,7 +84,7 @@
8585
8686 // None of the tokens we are interested in, so abort processing..
8787 //console.log( 'PostExpandParagraphHandler.onAny: ' + JSON.stringify( this.tokens, null , 2 ) );
88 - if ( this.newLines >= 2 && ! u.isBlock( token ) ) {
 88+ if ( this.newLines >= 2 && ! u.isBlockToken( token ) ) {
8989 return { tokens: [ { type: 'TAG', name: 'p' } ].concat( this._finish() ) };
9090 } else {
9191 return { tokens: this._finish() };

Status & tagging log