mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 11:16:51 +00:00
Merge "Filter out auto-generated reference lists"
This commit is contained in:
commit
0242dedff9
|
@ -122,8 +122,18 @@ ve.ce.MWTransclusionNode.prototype.onParseSuccess = function ( deferred, respons
|
|||
|
||||
// Work around https://github.com/jquery/jquery/issues/1997
|
||||
contentNodes = $.parseHTML( response.visualeditor.content, this.getModelHtmlDocument() ) || [];
|
||||
// Filter out auto-generated items, e.g. reference lists
|
||||
contentNodes = contentNodes.filter( function ( node ) {
|
||||
var dataMw = node.nodeType === Node.ELEMENT_NODE &&
|
||||
node.hasAttribute( 'data-mw' ) &&
|
||||
JSON.parse( node.getAttribute( 'data-mw' ) );
|
||||
if ( dataMw && dataMw.autoGenerated ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} );
|
||||
// HACK: if $content consists of a single paragraph, unwrap it.
|
||||
// We have to do this because the PHP parser wraps everything in <p>s, and inline templates
|
||||
// We have to do this because the parser wraps everything in <p>s, and inline templates
|
||||
// will render strangely when wrapped in <p>s.
|
||||
if ( contentNodes.length === 1 && contentNodes[ 0 ].nodeName.toLowerCase() === 'p' ) {
|
||||
contentNodes = Array.prototype.slice.apply( contentNodes[ 0 ].childNodes );
|
||||
|
|
|
@ -95,21 +95,22 @@ ve.ui.MWWikitextStringTransferHandler.prototype.process = function () {
|
|||
|
||||
// Don't immediately chain, as this.parsoidRequest must be abortable
|
||||
this.parsoidRequest.then( function ( response ) {
|
||||
var doc, surface;
|
||||
var htmlDoc, doc, surface;
|
||||
|
||||
if ( ve.getProp( response, 'visualeditor', 'result' ) !== 'success' ) {
|
||||
return failure();
|
||||
}
|
||||
|
||||
doc = handler.surface.getModel().getDocument().newFromHtml(
|
||||
response.visualeditor.content,
|
||||
{
|
||||
external: {
|
||||
// Blacklist reference lists as they were likely generated by mistake, see T101553
|
||||
blacklist: [ 'mwReferencesList' ]
|
||||
}
|
||||
// No additional sanitization, since HTML is from Parsoid
|
||||
htmlDoc = ve.createDocumentFromHtml( response.visualeditor.content );
|
||||
// Filter out auto-generated items, e.g. reference lists
|
||||
$( htmlDoc.body ).find( '[data-mw]' ).each( function () {
|
||||
var dataMw = JSON.parse( this.getAttribute( 'data-mw' ) );
|
||||
if ( dataMw.autoGenerated ) {
|
||||
this.remove();
|
||||
}
|
||||
);
|
||||
} );
|
||||
|
||||
doc = handler.surface.getModel().getDocument().newFromHtml( htmlDoc );
|
||||
|
||||
if ( !doc.data.hasContent() ) {
|
||||
return failure();
|
||||
|
|
Loading…
Reference in a new issue