mediawiki-extensions-Visual.../modules/parser/ext.Util.js

69 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* General utilities for token transforms
2012-01-17 20:01:21 +00:00
* XXX: move this to MWParserEnvironment?
*/
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-02-01 18:37:48 +00:00
if ( token.constructor === TagTk ||
token.constructor === EndTagTk ||
token.constructor === SelfclosingTagTk ) {
2012-01-17 18:30:22 +00:00
return this.isBlockTag( token.name.toLowerCase() );
} 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!
2012-01-17 18:30:22 +00:00
case 'pre':
case 'center':
case 'blockquote':
case 'h1':
case 'h2':
case 'h3':
case 'h4':
case 'h5':
case 'h6':
return true;
default:
return false;
}
};
if (typeof module == "object") {
module.exports.Util = Util;
}