C. Scott Ananian has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/395831 )
Change subject: Strip legacy section IDs from inside headings ...................................................................... Strip legacy section IDs from inside headings We emit <span id="..." typeof="mw:FallbackId"></span> inside headings when necessary to provide backward compatibility with pre-HTML5 section ids. These are mostly harmless inside VE --- they become hidden alienated nodes, which are then safely ignored by Parsoid during html2wt even if they manage to migrate outside of a heading --- but it's a little safer to strip them. Change-Id: I07d0fcf54427ab02d4930cff183d3e5579a99306 --- M modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js M modules/ve-mw/init/ve.init.mw.Target.js M modules/ve-mw/ve.MWutils.js 3 files changed, 18 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/31/395831/1 diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js b/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js index cd5028b..2d0567b 100644 --- a/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js +++ b/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js @@ -101,6 +101,7 @@ // Unwrap Parsoid sections (which probably shouldn't exist: T181226) contentNodes.forEach( function ( node ) { wrapper.appendChild( node ); } ); ve.unwrapParsoidSections( wrapper ); + ve.stripLegacyHeadingIds( wrapper ); contentNodes = Array.prototype.slice.call( wrapper.childNodes ); function isAutoGenerated( node ) { diff --git a/modules/ve-mw/init/ve.init.mw.Target.js b/modules/ve-mw/init/ve.init.mw.Target.js index 682e786..f08ca5e 100644 --- a/modules/ve-mw/init/ve.init.mw.Target.js +++ b/modules/ve-mw/init/ve.init.mw.Target.js @@ -198,6 +198,8 @@ doc = ve.parseXhtml( documentString ); // Strip Parsoid sections ve.unwrapParsoidSections( doc.body ); + // Strip legacy section IDs + ve.stripLegacyHeadingIds( doc.body ); } // Fix relative or missing base URL if needed this.fixBase( doc ); diff --git a/modules/ve-mw/ve.MWutils.js b/modules/ve-mw/ve.MWutils.js index 40d239e..732b08f 100644 --- a/modules/ve-mw/ve.MWutils.js +++ b/modules/ve-mw/ve.MWutils.js @@ -44,3 +44,18 @@ parent.removeChild( section ); } ); }; + +/** + * Strip legacy (non-HTML5) section IDs from inside headings. + * + * @param {HTMLElement} element Parent element, e.g. document body + */ +ve.stripLegacyHeadingIds = function ( element ) { + return; + Array.prototype.forEach.call( element.querySelectorAll( 'span[typeof="mw:FallbackId"][id]:first-child:empty' ), function ( legacySpan ) { + var parent = legacySpan.parentNode; + if ( /^H[1-6]$/.test(parent.tagName || '') ) { + parent.removeChild( legacySpan ); + } + } ); +}; -- To view, visit https://gerrit.wikimedia.org/r/395831 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I07d0fcf54427ab02d4930cff183d3e5579a99306 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: C. Scott Ananian <canan...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits