2016-06-14 22:27:44 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MediaWiki utilities.
|
|
|
|
*
|
2017-01-03 16:58:33 +00:00
|
|
|
* @copyright 2011-2017 VisualEditor Team and others; see http://ve.mit-license.org
|
2016-06-14 22:27:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class ve
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode a URI component into a mediawiki article title
|
|
|
|
*
|
|
|
|
* N.B. Illegal article titles can result from fairly reasonable input (e.g. "100%25beef");
|
|
|
|
* see https://phabricator.wikimedia.org/T137847 .
|
|
|
|
*
|
|
|
|
* @param {string} s String to decode
|
|
|
|
* @param {boolean} [preserveUnderscores] Don't convert underscores to spaces
|
|
|
|
* @return {string} Decoded string, or original string if decodeURIComponent failed
|
|
|
|
*/
|
|
|
|
ve.decodeURIComponentIntoArticleTitle = function ( s, preserveUnderscores ) {
|
|
|
|
try {
|
|
|
|
s = decodeURIComponent( s );
|
|
|
|
} catch ( e ) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
if ( preserveUnderscores ) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
return s.replace( /_/g, ' ' );
|
|
|
|
};
|
2017-10-26 19:27:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unwrap Parsoid sections
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} element Parent element, e.g. document body
|
|
|
|
*/
|
|
|
|
ve.unwrapParsoidSections = function ( element ) {
|
|
|
|
Array.prototype.forEach.call( element.querySelectorAll( 'section[data-mw-section-id]' ), function ( section ) {
|
|
|
|
var parent = section.parentNode;
|
|
|
|
while ( section.firstChild ) {
|
|
|
|
parent.insertBefore( section.firstChild, section );
|
|
|
|
}
|
|
|
|
parent.removeChild( section );
|
|
|
|
} );
|
|
|
|
};
|