From 110db0e3c7792205071c0602e9b93534b7cd06fe Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Wed, 19 Jan 2022 01:26:14 +0000 Subject: [PATCH] Remove conflicting section IDs in diff views Bug: T218492 Change-Id: I84c60a36859190efc37c68e380ae44225be06d9c --- modules/ve-mw/preinit/ve.init.mw.DiffPage.init.js | 2 ++ modules/ve-mw/preinit/ve.utils.parsoid.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/modules/ve-mw/preinit/ve.init.mw.DiffPage.init.js b/modules/ve-mw/preinit/ve.init.mw.DiffPage.init.js index 6e3efa53b9..9f749202ca 100644 --- a/modules/ve-mw/preinit/ve.init.mw.DiffPage.init.js +++ b/modules/ve-mw/preinit/ve.init.mw.DiffPage.init.js @@ -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 = { diff --git a/modules/ve-mw/preinit/ve.utils.parsoid.js b/modules/ve-mw/preinit/ve.utils.parsoid.js index 26b81a519a..df36270373 100644 --- a/modules/ve-mw/preinit/ve.utils.parsoid.js +++ b/modules/ve-mw/preinit/ve.utils.parsoid.js @@ -196,6 +196,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 ); @@ -205,6 +206,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' ); + } + } ); }; /**