mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-01 01:16:30 +00:00
MWNumberedExternalLinkNode: set an explicit type
This lets copy-paste between documents retain the numbered status rather than falling back on pasting "<a>[3]</a>". Update the part of LinkCache which selects on mw:ExtLink, so it will handle possible multiple values in the link rel. Bug: T188429 Change-Id: Ia5e4c9fa45e94da9cbfcd2a42d017d0fda1c511f
This commit is contained in:
parent
4c759e2587
commit
795b428477
|
@ -37,13 +37,16 @@ ve.dm.MWNumberedExternalLinkNode.static.isContent = true;
|
||||||
|
|
||||||
ve.dm.MWNumberedExternalLinkNode.static.matchTagNames = [ 'a' ];
|
ve.dm.MWNumberedExternalLinkNode.static.matchTagNames = [ 'a' ];
|
||||||
|
|
||||||
ve.dm.MWNumberedExternalLinkNode.static.matchRdfaTypes = [ 'mw:ExtLink' ];
|
ve.dm.MWNumberedExternalLinkNode.static.matchRdfaTypes = [ 'mw:ExtLink', 'mw:NumberedLink' ];
|
||||||
|
|
||||||
ve.dm.MWNumberedExternalLinkNode.static.blacklistedAnnotationTypes = [ 'link' ];
|
ve.dm.MWNumberedExternalLinkNode.static.blacklistedAnnotationTypes = [ 'link' ];
|
||||||
|
|
||||||
ve.dm.MWNumberedExternalLinkNode.static.matchFunction = function ( domElement ) {
|
ve.dm.MWNumberedExternalLinkNode.static.matchFunction = function ( domElement ) {
|
||||||
// Must be empty
|
// Must be empty, or explicitly flagged as a numbered link. We can't just
|
||||||
return domElement.childNodes.length === 0;
|
// rely on emptiness, because we give the link content for cross-document
|
||||||
|
// pastes so it won't be pruned. (And so it'll be functional in non-wiki
|
||||||
|
// contexts.)
|
||||||
|
return domElement.childNodes.length === 0 || domElement.getAttribute( 'rel' ).indexOf( 'mw:NumberedLink' ) !== -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
ve.dm.MWNumberedExternalLinkNode.static.toDataElement = function ( domElements ) {
|
ve.dm.MWNumberedExternalLinkNode.static.toDataElement = function ( domElements ) {
|
||||||
|
@ -77,7 +80,7 @@ ve.dm.MWNumberedExternalLinkNode.static.toDomElements = function ( dataElement,
|
||||||
domElement.appendChild( doc.createTextNode( '[' + counter + ']' ) );
|
domElement.appendChild( doc.createTextNode( '[' + counter + ']' ) );
|
||||||
}
|
}
|
||||||
domElement.setAttribute( 'href', dataElement.attributes.href );
|
domElement.setAttribute( 'href', dataElement.attributes.href );
|
||||||
domElement.setAttribute( 'rel', 'mw:ExtLink' );
|
domElement.setAttribute( 'rel', 'mw:ExtLink mw:NumberedLink' );
|
||||||
return [ domElement ];
|
return [ domElement ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ ve.init.mw.LinkCache.prototype.styleParsoidElements = function ( $elements, doc
|
||||||
|
|
||||||
// TODO: Remove when fixed upstream in Parsoid (T58756)
|
// TODO: Remove when fixed upstream in Parsoid (T58756)
|
||||||
$elements
|
$elements
|
||||||
.find( 'a[rel="mw:ExtLink"]' ).addBack( 'a[rel="mw:ExtLink"]' )
|
.find( 'a[rel~="mw:ExtLink"]' ).addBack( 'a[rel~="mw:ExtLink"]' )
|
||||||
.addClass( 'external' );
|
.addClass( 'external' );
|
||||||
|
|
||||||
// TODO: Remove when moved upstream into Parsoid or another service (T64803)
|
// TODO: Remove when moved upstream into Parsoid or another service (T64803)
|
||||||
|
|
|
@ -1109,7 +1109,7 @@ ve.dm.mwExample.domToDataCases = {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'numbered external link (empty mw:Extlink)': {
|
'numbered external link (empty mw:Extlink)': {
|
||||||
body: '<p>Foo<a rel="mw:ExtLink" href="http://www.example.com"></a>Bar</p>',
|
body: '<p>Foo<a rel="mw:ExtLink mw:NumberedLink" href="http://www.example.com"></a>Bar</p>',
|
||||||
data: [
|
data: [
|
||||||
{ type: 'paragraph' },
|
{ type: 'paragraph' },
|
||||||
'F', 'o', 'o',
|
'F', 'o', 'o',
|
||||||
|
@ -1125,7 +1125,7 @@ ve.dm.mwExample.domToDataCases = {
|
||||||
{ type: 'internalList' },
|
{ type: 'internalList' },
|
||||||
{ type: '/internalList' }
|
{ type: '/internalList' }
|
||||||
],
|
],
|
||||||
clipboardBody: '<p>Foo<a rel="mw:ExtLink" href="http://www.example.com">[1]</a>Bar</p>'
|
clipboardBody: '<p>Foo<a rel="mw:ExtLink mw:NumberedLink" href="http://www.example.com">[1]</a>Bar</p>'
|
||||||
},
|
},
|
||||||
'URL link': {
|
'URL link': {
|
||||||
body: '<p><a rel="mw:ExtLink" href="http://www.mediawiki.org/">mw</a></p>',
|
body: '<p><a rel="mw:ExtLink" href="http://www.mediawiki.org/">mw</a></p>',
|
||||||
|
|
Loading…
Reference in a new issue