Merge "Add handling for mw:DisplaySpace"

This commit is contained in:
jenkins-bot 2020-01-08 22:26:08 +00:00 committed by Gerrit Code Review
commit bc2204b6c0
2 changed files with 36 additions and 3 deletions

View file

@ -31,16 +31,28 @@ ve.dm.MWEntityNode.static.isContent = true;
ve.dm.MWEntityNode.static.matchTagNames = [ 'span' ];
ve.dm.MWEntityNode.static.matchRdfaTypes = [ 'mw:Entity' ];
ve.dm.MWEntityNode.static.matchRdfaTypes = [ 'mw:Entity', 'mw:DisplaySpace' ];
ve.dm.MWEntityNode.static.allowedRdfaTypes = [ 'mw:Placeholder' ];
ve.dm.MWEntityNode.static.toDataElement = function ( domElements ) {
return { type: this.name, attributes: { character: domElements[ 0 ].textContent } };
var dataElement = {
type: this.name,
attributes: {
character: domElements[ 0 ].textContent
}
};
if ( domElements[ 0 ].getAttribute( 'typeof' ).indexOf( 'mw:DisplaySpace' ) !== -1 ) {
dataElement.attributes.displaySpace = true;
}
return dataElement;
};
ve.dm.MWEntityNode.static.toDomElements = function ( dataElement, doc ) {
var domElement = doc.createElement( 'span' ),
textNode = doc.createTextNode( dataElement.attributes.character );
domElement.setAttribute( 'typeof', 'mw:Entity' );
domElement.setAttribute( 'typeof',
dataElement.attributes.displaySpace ? 'mw:DisplaySpace mw:Placeholder' : 'mw:Entity' );
domElement.appendChild( textNode );
return [ domElement ];
};

View file

@ -1767,6 +1767,27 @@ ve.dm.mwExample.domToDataCases = {
{ type: '/internalList' }
]
},
'mw:DisplaySpace': {
body: '<p>a<span typeof="mw:DisplaySpace mw:Placeholder">&nbsp;</span>: b</p>',
data: [
{ type: 'paragraph' },
'a',
{
type: 'mwEntity',
attributes: {
character: '\u00a0',
displaySpace: true
}
},
{ type: '/mwEntity' },
':',
' ',
'b',
{ type: '/paragraph' },
{ type: 'internalList' },
{ type: '/internalList' }
]
},
'wrapping with mw:Entity': {
body: 'a<span typeof="mw:Entity">¢</span>b<span typeof="mw:Entity">¥</span><span typeof="mw:Entity">™</span>',
data: [