mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
6bd7ca1e75
* 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
56 lines
937 B
JavaScript
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;
|
|
}
|