mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 23:05:35 +00:00
21ff108c28
Parsoid outputs rel="mw:wikiLink" or rel="mw:extLink", so we convert that to link/wikiLink and wiki/extLink respectively. Also preserve the data-mw attribute; we probably need to do this more generally but this'll do for now. Change-Id: I32e570bffa5a73a733a120d52cfd8b75d3191e02
53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
/**
|
|
* DataModel annotation for a link.
|
|
*
|
|
* @class
|
|
* @constructor
|
|
* @extends {ve.dm.Annotation}
|
|
*/
|
|
ve.dm.LinkAnnotation = function() {
|
|
// Inheritance
|
|
ve.dm.Annotation.call( this );
|
|
};
|
|
|
|
/* Static Members */
|
|
|
|
/**
|
|
* Converters.
|
|
*
|
|
* @see {ve.dm.Converter}
|
|
* @static
|
|
* @member
|
|
*/
|
|
ve.dm.LinkAnnotation.converters = {
|
|
'domElementTypes': ['a'],
|
|
'toDomElement': function( subType, annotation ) {
|
|
if ( annotation.type ) {
|
|
var link = document.createElement( 'a' );
|
|
link.setAttribute( 'href', annotation.data.href );
|
|
link.setAttribute( 'data-mw', annotation.data.mw );
|
|
if ( subType === 'wikiLink' || subType === 'extLink' ) {
|
|
link.setAttribute( 'rel', 'mw:' + subType );
|
|
}
|
|
return link;
|
|
}
|
|
},
|
|
'toDataAnnotation': function( tag, element ) {
|
|
return {
|
|
'type': 'link/' + ( element.getAttribute( 'rel' ).split( ':' )[1] || 'unknown' ),
|
|
'data': {
|
|
'href': element.getAttribute( 'href' ),
|
|
'mw': element.getAttribute( 'data-mw' )
|
|
}
|
|
};
|
|
}
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.dm.annotationFactory.register( 'link', ve.dm.LinkAnnotation );
|
|
|
|
/* Inheritance */
|
|
|
|
ve.extendClass( ve.dm.LinkAnnotation, ve.dm.Annotation );
|