2012-01-17 18:22:10 +00:00
|
|
|
/**
|
|
|
|
* General utilities for token transforms
|
2012-01-17 20:01:21 +00:00
|
|
|
* XXX: move this to MWParserEnvironment?
|
2012-01-17 18:22:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
function Util () {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a token is block-level or not
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {Object} token: The token to check
|
|
|
|
* @returns {Boolean}: True if token is block-level, false otherwise.
|
|
|
|
*/
|
2012-01-17 18:30:22 +00:00
|
|
|
Util.prototype.isBlockToken = function ( token ) {
|
2012-01-17 18:22:10 +00:00
|
|
|
if ( token.type === 'TAG' ||
|
|
|
|
token.type === 'ENDTAG' ||
|
|
|
|
token.type === 'SELFCLOSINGTAG' ) {
|
2012-01-17 18:30:22 +00:00
|
|
|
return this.isBlockTag( token.name.toLowerCase() );
|
2012-01-17 18:22:10 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-17 18:30:22 +00:00
|
|
|
/**
|
|
|
|
* Determine if a tag name is block-level or not
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {String} name: Lower-case tag name
|
|
|
|
* @returns {Boolean}: True if tag is block-level, false otherwise.
|
|
|
|
*/
|
|
|
|
Util.prototype.isBlockTag = function ( name ) {
|
|
|
|
switch ( name ) {
|
|
|
|
case 'div':
|
|
|
|
case 'table':
|
|
|
|
case 'td':
|
|
|
|
case 'tr':
|
|
|
|
case 'tbody':
|
|
|
|
case 'p':
|
|
|
|
case 'ul':
|
|
|
|
case 'ol':
|
|
|
|
case 'li':
|
|
|
|
case 'dl':
|
|
|
|
case 'dt':
|
|
|
|
case 'dd':
|
|
|
|
case 'img': // hmm!
|
|
|
|
case 'pre':
|
|
|
|
case 'center':
|
|
|
|
case 'blockquote':
|
|
|
|
case 'h1':
|
|
|
|
case 'h2':
|
|
|
|
case 'h3':
|
|
|
|
case 'h4':
|
|
|
|
case 'h5':
|
|
|
|
case 'h6':
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-17 18:22:10 +00:00
|
|
|
if (typeof module == "object") {
|
|
|
|
module.exports.Util = Util;
|
|
|
|
}
|