mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 06:24:08 +00:00
Merge "Move restbaseId stripping to ve.utils.parsoid"
This commit is contained in:
commit
1bc368e01d
|
@ -61,7 +61,7 @@ ve.init.mw.Platform.prototype.notify = function ( message, title, options ) {
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.init.mw.Platform.prototype.getMetadataIdRegExp = function () {
|
||||
return /^mw[a-zA-Z0-9\-_]{2,6}$/;
|
||||
return mw.libs.ve.restbaseIdRegExp;
|
||||
};
|
||||
|
||||
/** @inheritdoc */
|
||||
|
|
|
@ -35,17 +35,10 @@
|
|||
// This method is only called after actually loading these, see `parseDocumentModulePromise`
|
||||
// eslint-disable-next-line no-undef
|
||||
targetClass = ve.init.mw.ArticleTarget,
|
||||
// eslint-disable-next-line no-undef
|
||||
metadataIdRegExp = ve.init.platform.getMetadataIdRegExp(),
|
||||
data = response ? ( response.visualeditor || response.visualeditoredit ) : null;
|
||||
if ( data && typeof data.content === 'string' ) {
|
||||
doc = targetClass.static.parseDocument( data.content, 'visual', section, section !== null );
|
||||
// Strip RESTBase IDs
|
||||
Array.prototype.forEach.call( doc.querySelectorAll( '[id^="mw"]' ), function ( element ) {
|
||||
if ( element.id.match( metadataIdRegExp ) ) {
|
||||
element.removeAttribute( 'id' );
|
||||
}
|
||||
} );
|
||||
mw.libs.ve.stripRestbaseIds( doc );
|
||||
return targetClass.static.createModelFromDom( doc, 'visual' );
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -82,6 +82,17 @@ mw.libs.ve.stripParsoidFallbackIds = function ( element ) {
|
|||
} );
|
||||
};
|
||||
|
||||
mw.libs.ve.restbaseIdRegExp = /^mw[a-zA-Z0-9\-_]{2,6}$/;
|
||||
|
||||
mw.libs.ve.stripRestbaseIds = function ( doc ) {
|
||||
var restbaseIdRegExp = mw.libs.ve.restbaseIdRegExp;
|
||||
Array.prototype.forEach.call( doc.querySelectorAll( '[id^="mw"]' ), function ( element ) {
|
||||
if ( element.id.match( restbaseIdRegExp ) ) {
|
||||
element.removeAttribute( 'id' );
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Fix fragment links which should be relative to the current document
|
||||
*
|
||||
|
|
|
@ -673,7 +673,7 @@ ve.dm.mwExample.domToDataCases = {
|
|||
fromDataBody: '<b>a</b><b data-parsoid="1">bx</b><b data-parsoid="2">c</b> ' +
|
||||
'<b>dd</b>'
|
||||
},
|
||||
'adjacent annotations (Parsoid IDs)': {
|
||||
'adjacent annotations (RESTBase IDs)': {
|
||||
preserveAnnotationDomElements: true,
|
||||
body: '<b>a</b><b id="mwAB">b</b><b id="mwCD">c</b> ' +
|
||||
'<b>d</b><b>d</b>',
|
||||
|
|
|
@ -107,7 +107,7 @@ ve.ui.MWWikitextStringTransferHandler.prototype.process = function () {
|
|||
|
||||
// Don't immediately chain, as this.parsoidRequest must be abortable
|
||||
this.parsoidRequest.then( function ( response ) {
|
||||
var htmlDoc, doc, surface, elementsWithIds, len;
|
||||
var htmlDoc, doc, surface;
|
||||
|
||||
if ( ve.getProp( response, 'visualeditor', 'result' ) !== 'success' ) {
|
||||
return failure();
|
||||
|
@ -116,12 +116,7 @@ ve.ui.MWWikitextStringTransferHandler.prototype.process = function () {
|
|||
htmlDoc = ve.createDocumentFromHtml( response.visualeditor.content );
|
||||
|
||||
// Strip RESTBase IDs
|
||||
elementsWithIds = htmlDoc.querySelectorAll( '[id]' );
|
||||
for ( i = 0, len = elementsWithIds.length; i < len; i++ ) {
|
||||
if ( elementsWithIds[ i ].getAttribute( 'id' ).match( ve.init.platform.getMetadataIdRegExp() ) ) {
|
||||
elementsWithIds[ i ].removeAttribute( 'id' );
|
||||
}
|
||||
}
|
||||
mw.libs.ve.stripRestbaseIds( htmlDoc );
|
||||
|
||||
// Strip legacy IDs, for example in section headings
|
||||
mw.libs.ve.stripParsoidFallbackIds( htmlDoc.body );
|
||||
|
|
Loading…
Reference in a new issue