mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-27 04:06:51 +00:00
Added 'href' key to anonymous KV wikilink and isbn attribute.
* This makes wikilink attrs more similar to ext links. * Added 'content' key to ISBN links, but couldn't add it to regular wikilinks yet because of complexity of how they are handled in the rest of the pipeline. Changing this requires fixing up other parts down the pipeline -- something for later. * Fixed up wikilink handler to use named lookup for 'href' and 'tail' rather than positional lookup. Content lookup is still positional as before. Change-Id: I657b1f338d38df3cfdfa99f27ac46e7fe1c9fd65
This commit is contained in:
parent
6b8a4b386e
commit
f558f3a33c
|
@ -27,12 +27,11 @@ WikiLinkHandler.prototype.rank = 1.15; // after AttributeExpander
|
|||
|
||||
WikiLinkHandler.prototype.onWikiLink = function ( token, frame, cb ) {
|
||||
var env = this.manager.env,
|
||||
href = token.attribs[0].v,
|
||||
hrefStr = env.tokensToString( href );
|
||||
var title = env.makeTitleFromPrefixedText(hrefStr);
|
||||
href = env.tokensToString( Util.lookupKV( token.attribs, 'href' ).v ),
|
||||
title = env.makeTitleFromPrefixedText(href);
|
||||
|
||||
if ( title.ns.isFile() ) {
|
||||
cb( this.renderFile( token, frame, cb, hrefStr, title ) );
|
||||
cb( this.renderFile( token, frame, cb, href, title ) );
|
||||
} else if ( title.ns.isCategory() ) {
|
||||
// Simply round-trip category links for now
|
||||
cb( { tokens: [
|
||||
|
@ -54,11 +53,12 @@ WikiLinkHandler.prototype.onWikiLink = function ( token, frame, cb ) {
|
|||
),
|
||||
content = token.attribs.slice(2);
|
||||
if ( href !== normalizedHref ) {
|
||||
obj.dataAttribs.sHref = hrefStr;
|
||||
obj.dataAttribs.sHref = href;
|
||||
}
|
||||
//console.warn('content: ' + JSON.stringify( content, null, 2 ) );
|
||||
|
||||
// XXX: handle trail
|
||||
if ( content.length ) {
|
||||
if ( content.length > 0 ) {
|
||||
var out = [];
|
||||
for ( var i = 0, l = content.length; i < l ; i++ ) {
|
||||
out = out.concat( content[i].v );
|
||||
|
@ -68,11 +68,11 @@ WikiLinkHandler.prototype.onWikiLink = function ( token, frame, cb ) {
|
|||
}
|
||||
content = out;
|
||||
} else {
|
||||
content = [ Util.decodeURI(hrefStr) ];
|
||||
content = [ Util.decodeURI(href) ];
|
||||
obj.dataAttribs.gc = 1;
|
||||
}
|
||||
|
||||
var tail = token.attribs[1].v;
|
||||
var tail = Util.lookupKV( token.attribs, 'tail' ).v;
|
||||
if ( tail ) {
|
||||
obj.dataAttribs.tail = tail;
|
||||
content.push( tail );
|
||||
|
@ -89,10 +89,8 @@ WikiLinkHandler.prototype.renderFile = function ( token, frame, cb, fileName, ti
|
|||
// distinguish media types
|
||||
// if image: parse options
|
||||
|
||||
// Slice off the target and tail
|
||||
var content = token.attribs.slice(2);
|
||||
|
||||
|
||||
var MD5 = new jshashes.MD5(),
|
||||
hash = MD5.hex( title.key ),
|
||||
// TODO: Hackhack.. Move to proper test harness setup!
|
||||
|
@ -358,8 +356,7 @@ ExternalLinkHandler.prototype._isImageLink = function ( href ) {
|
|||
ExternalLinkHandler.prototype.onUrlLink = function ( token, frame, cb ) {
|
||||
var env = this.manager.env,
|
||||
href = Util.sanitizeURI(
|
||||
env.tokensToString( Util.lookupKV( token.attribs, 'href' ).v )
|
||||
);
|
||||
env.tokensToString( Util.lookupKV( token.attribs, 'href' ).v ));
|
||||
if ( this._isImageLink( href ) ) {
|
||||
cb( { tokens: [ new SelfclosingTagTk( 'img',
|
||||
[
|
||||
|
@ -391,9 +388,8 @@ ExternalLinkHandler.prototype.onUrlLink = function ( token, frame, cb ) {
|
|||
// Bracketed external link
|
||||
ExternalLinkHandler.prototype.onExtLink = function ( token, manager, cb ) {
|
||||
var env = this.manager.env,
|
||||
href = env.tokensToString( Util.lookupKV( token.attribs, 'href' ).v ),
|
||||
href = Util.sanitizeURI(env.tokensToString( Util.lookupKV( token.attribs, 'href' ).v )),
|
||||
content= Util.lookupKV( token.attribs, 'content' ).v;
|
||||
href = Util.sanitizeURI( href );
|
||||
//console.warn('extlink href: ' + href );
|
||||
//console.warn( 'content: ' + JSON.stringify( content, null, 2 ) );
|
||||
// validate the href
|
||||
|
|
|
@ -715,9 +715,9 @@ isbn
|
|||
|
||||
return [
|
||||
new SelfclosingTagTk( 'wikilink', [
|
||||
new KV('', 'Special:BookSources/' + isbn.replace(/[^\d]/g, '')),
|
||||
new KV('', 'ISBN ' + isbn),
|
||||
new KV('href', 'Special:BookSources/' + isbn.replace(/[^\d]/g, '')),
|
||||
new KV('tail', ''),
|
||||
new KV('content', 'ISBN ' + isbn),
|
||||
],
|
||||
{tsr: [pos0, pos]})
|
||||
];
|
||||
|
@ -979,7 +979,7 @@ wikilink
|
|||
{
|
||||
var obj = new SelfclosingTagTk( 'wikilink' ),
|
||||
textTokens = [];
|
||||
obj.attribs.push( new KV('', target) );
|
||||
obj.attribs.push( new KV('href', target) );
|
||||
obj.dataAttribs = {
|
||||
tsr: [pos0, pos],
|
||||
contentPos: lcontent.pos,
|
||||
|
|
Loading…
Reference in a new issue