Unwrap Parsoid sections

Section wrapping will be introduced in I0f4c19f7.

Change-Id: I43ced131d07a20318af37e830318e30db2eb451f
This commit is contained in:
Ed Sanders 2017-10-26 20:27:21 +01:00
parent 38dba57e95
commit 267d60f61a
2 changed files with 17 additions and 0 deletions

View file

@ -196,6 +196,8 @@ ve.init.mw.Target.static.parseDocument = function ( documentString, mode ) {
} else {
// Parsoid documents are XHTML so we can use parseXhtml which fixed some IE issues.
doc = ve.parseXhtml( documentString );
// Strip Parsoid sections
ve.unwrapParsoidSections( doc.body );
}
// Fix relative or missing base URL if needed
this.fixBase( doc );

View file

@ -29,3 +29,18 @@ ve.decodeURIComponentIntoArticleTitle = function ( s, preserveUnderscores ) {
}
return s.replace( /_/g, ' ' );
};
/**
* 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 );
} );
};