mediawiki-extensions-Visual.../modules/parser/ext.Util.js
Gabriel Wicke 6bd7ca1e75 Misc improvements, now 196 parser tests passing.
* Add handler for post-expand paragraph wrapping on token stream, to handle
  things like comments on its own line post-expand
* Add general Util module
* Fix self-closing tag handling in HTML5 tree builder
2012-01-17 18:22:10 +00:00

56 lines
937 B
JavaScript

/**
* General utilities for token transforms
*/
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.
*/
Util.prototype.isBlock = function ( token ) {
if ( token.type === 'TAG' ||
token.type === 'ENDTAG' ||
token.type === 'SELFCLOSINGTAG' ) {
switch (token.name.toLowerCase()) {
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;
}
} else {
return false;
}
};
if (typeof module == "object") {
module.exports.Util = Util;
}