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:
Subramanya Sastry 2012-06-01 23:29:39 -05:00
parent 413fc5e043
commit 8f216af2f5
2 changed files with 9 additions and 2 deletions

View file

@ -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 );
}

View file

@ -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 );
}
}