mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-26 19:56:49 +00:00
Handle link tails properly.
- Added a tail json attribute for wikiLinks - During serialization, this attribute is used to strip the tail from the link target and render it after the link [[hen]]s ==> <a ... data-mw="{gc:1, tail: 's'}" ...>hens</a> ==> [[hen]]s - 2 more roundtrip tests green Change-Id: I84f3dabaf0271f7a67641a00148467daa8310eb0
This commit is contained in:
parent
413fc5e043
commit
8f216af2f5
|
@ -64,7 +64,7 @@ WikiLinkHandler.prototype.onWikiLink = function ( token, frame, cb ) {
|
|||
obj.dataAttribs.gc = 1;
|
||||
}
|
||||
if ( tail ) {
|
||||
// TODO: make this round-trippable
|
||||
obj.dataAttribs.tail = tail;
|
||||
content.push( tail );
|
||||
}
|
||||
|
||||
|
|
|
@ -121,6 +121,10 @@ WSP._linkHandler = function( state, token ) {
|
|||
);
|
||||
|
||||
if ( attribDict.rel === 'mw:wikiLink' ) {
|
||||
if (token.dataAttribs.tail) {
|
||||
state.linkTail = token.dataAttribs.tail;
|
||||
}
|
||||
|
||||
if ( token.dataAttribs.gc ) {
|
||||
return '[[';
|
||||
} else {
|
||||
|
@ -153,8 +157,10 @@ WSP._linkEndHandler = function( state, token ) {
|
|||
var attribDict = state.env.KVtoHash( token.attribs );
|
||||
if ( attribDict.rel && attribDict.href !== undefined ) {
|
||||
if ( attribDict.rel === 'mw:wikiLink' ) {
|
||||
var retVal = "]]" + (state.linkTail ? state.linkTail : "");
|
||||
state.linkTail = null;
|
||||
state.dropContent = false;
|
||||
return ']]';
|
||||
return retVal;
|
||||
} else if ( attribDict.rel === 'mw:extLink' ) {
|
||||
if ( token.dataAttribs.stx === 'urllink' ) {
|
||||
state.dropContent = false;
|
||||
|
@ -402,6 +408,7 @@ WSP._serializeToken = function ( state, token ) {
|
|||
state.precedingNewlineCount = 0;
|
||||
}
|
||||
if ( ! dropContent || ! state.dropContent ) {
|
||||
if (state.linkTail) res = res.replace(new RegExp(state.linkTail + "$"), "");
|
||||
state.chunkCB( res );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue