Merge "Fix Parsoid HTML of broken images"

This commit is contained in:
jenkins-bot 2021-02-26 19:54:52 +00:00 committed by Gerrit Code Review
commit 8e5af5aafd
2 changed files with 8 additions and 4 deletions

View file

@ -168,7 +168,7 @@ ve.dm.MWBlockImageNode.static.toDomElements = function ( data, doc, converter )
mediaClass = dataElement.attributes.mediaClass,
figure = doc.createElement( 'figure' ),
imgWrapper = doc.createElement( dataElement.attributes.href ? 'a' : 'span' ),
img = doc.createElement( this.typesToTags[ mediaClass ] ),
img = doc.createElement( dataElement.attributes.isError ? 'span' : this.typesToTags[ mediaClass ] ),
wrapper = doc.createElement( 'div' ),
classAttr = this.getClassAttrFromAttributes( dataElement.attributes ),
captionData = data.slice( 1, -1 );
@ -202,12 +202,14 @@ ve.dm.MWBlockImageNode.static.toDomElements = function ( data, doc, converter )
}
srcAttr = this.typesToSrcAttrs[ mediaClass ];
if ( srcAttr ) {
if ( srcAttr && !dataElement.attributes.isError ) {
img.setAttribute( srcAttr, dataElement.attributes.src );
}
// TODO: This does not make sense for broken images (when img is a span node)
img.setAttribute( 'width', width );
img.setAttribute( 'height', height );
img.setAttribute( 'resource', dataElement.attributes.resource );
// TODO: This does not make sense for broken images (when img is a span node)
if ( typeof dataElement.attributes.alt === 'string' ) {
img.setAttribute( 'alt', dataElement.attributes.alt );
}

View file

@ -149,16 +149,18 @@ ve.dm.MWInlineImageNode.static.toDomElements = function ( data, doc ) {
var firstChild, srcAttr,
mediaClass = data.attributes.mediaClass,
container = doc.createElement( data.attributes.tagName || 'span' ),
img = doc.createElement( this.typesToTags[ mediaClass ] ),
img = doc.createElement( data.attributes.isError ? 'span' : this.typesToTags[ mediaClass ] ),
classes = [],
originalClasses = data.attributes.originalClasses;
// TODO: This does not make sense for broken images (when img is a span node)
ve.setDomAttributes( img, data.attributes, [ 'width', 'height', 'resource' ] );
srcAttr = this.typesToSrcAttrs[ mediaClass ];
if ( srcAttr ) {
if ( srcAttr && !data.attributes.isError ) {
img.setAttribute( srcAttr, data.attributes.src );
}
// TODO: This does not make sense for broken images (when img is a span node)
if ( typeof data.attributes.alt === 'string' ) {
img.setAttribute( 'alt', data.attributes.alt );
}