Merge "Remove conflicting section IDs in diff views"

This commit is contained in:
jenkins-bot 2022-01-26 00:04:22 +00:00 committed by Gerrit Code Review
commit 3c7d81aa2f
2 changed files with 9 additions and 0 deletions

View file

@ -72,6 +72,8 @@
var diffElement = new ve.ui.DiffElement( visualDiffGenerator(), { classes: [ 've-init-mw-diffPage-diff' ] } );
diffElement.$document.addClass( 'mw-parser-output content' );
mw.libs.ve.fixFragmentLinks( diffElement.$document[ 0 ], mw.Title.newFromText( newPageName ), 'mw-diffpage-visualdiff-' );
progress.$element.addClass( 'oo-ui-element-hidden' );
$visualDiff.append( diffElement.$element );
lastDiff = {

View file

@ -127,6 +127,7 @@ mw.libs.ve.fixFragmentLinks = function ( container, docTitle, prefix ) {
// hasn't already been fixed (in which case it would be null)
if ( target ) {
target.setAttribute( 'id', prefix + fragment );
target.setAttribute( 'data-mw-id-fixed', '' );
}
}
el.setAttribute( 'href', '#' + prefix + fragment );
@ -136,6 +137,12 @@ mw.libs.ve.fixFragmentLinks = function ( container, docTitle, prefix ) {
}
}
} );
// Remove any section heading anchors which weren't fixed above (T218492)
Array.prototype.forEach.call( container.querySelectorAll( 'h1, h2, h3, h4, h5, h6' ), function ( el ) {
if ( el.hasAttribute( 'id' ) && !el.hasAttribute( 'data-mw-id-fixed' ) ) {
el.removeAttribute( 'id' );
}
} );
};
/**