Index: trunk/extensions/VisualEditor/modules/parser/ext.Util.js |
— | — | @@ -14,42 +14,54 @@ |
15 | 15 | * @param {Object} token: The token to check |
16 | 16 | * @returns {Boolean}: True if token is block-level, false otherwise. |
17 | 17 | */ |
18 | | -Util.prototype.isBlock = function ( token ) { |
| 18 | +Util.prototype.isBlockToken = function ( token ) { |
19 | 19 | if ( token.type === 'TAG' || |
20 | 20 | token.type === 'ENDTAG' || |
21 | 21 | 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() ); |
49 | 23 | } else { |
50 | 24 | return false; |
51 | 25 | } |
52 | 26 | }; |
53 | 27 | |
| 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 | + |
54 | 66 | if (typeof module == "object") { |
55 | 67 | module.exports.Util = Util; |
56 | 68 | } |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.DOMPostProcessor.js |
— | — | @@ -1,37 +1,9 @@ |
2 | 2 | /* Perform post-processing steps on an already-built HTML DOM. */ |
3 | 3 | |
4 | | -var events = require('events'); |
| 4 | +var events = require('events'), |
| 5 | + util = require('./ext.Util.js'), |
| 6 | + Util = new util.Util(); |
5 | 7 | |
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 | | - |
36 | 8 | // Quick HACK: define Node constants |
37 | 9 | // https://developer.mozilla.org/en/nodeType |
38 | 10 | var Node = { |
— | — | @@ -61,7 +33,7 @@ |
62 | 34 | (ctype === Node.COMMENT_NODE && inParagraph ) || |
63 | 35 | (ctype !== Node.TEXT_NODE && |
64 | 36 | ctype !== Node.COMMENT_NODE && |
65 | | - !isBlock(child.nodeName)) |
| 37 | + !Util.isBlockTag(child.nodeName.toLowerCase())) |
66 | 38 | ) |
67 | 39 | { |
68 | 40 | // wrap in paragraph |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.PostExpandParagraphHandler.js |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | |
86 | 86 | // None of the tokens we are interested in, so abort processing.. |
87 | 87 | //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 ) ) { |
89 | 89 | return { tokens: [ { type: 'TAG', name: 'p' } ].concat( this._finish() ) }; |
90 | 90 | } else { |
91 | 91 | return { tokens: this._finish() }; |