Take link fragments into account

TODO: Do we need to do anything special here to handle multiple hash symbols in a URL?

Bug: T112898
Change-Id: I4773cb04ae2533e8125bc55d9ebb606d63b3bf48
This commit is contained in:
Alex Monk 2016-08-06 01:18:56 +01:00
parent cf4c2d41b3
commit 818c6e4928

View file

@ -66,6 +66,9 @@ ve.dm.MWInternalLinkAnnotation.static.newFromTitle = function ( title ) {
// rather than an image inclusion or categorization
target = ':' + target;
}
if ( title.getFragment() ) {
target += '#' + title.getFragment();
}
return new ve.dm.MWInternalLinkAnnotation( {
type: 'link/mwInternal',
@ -147,7 +150,13 @@ ve.dm.MWInternalLinkAnnotation.static.getHref = function ( dataElement ) {
}
} else {
// Don't escape slashes in the title; they represent subpages.
href = title.split( '/' ).map( encodeURIComponent ).join( '/' );
href = title.split( /(\/|#)/ ).map( function ( part ) {
if ( part === '/' || part === '#' ) {
return part;
} else {
return encodeURIComponent( part );
}
} ).join( '' );
}
return href;
};