Start to handle links

Change-Id: I1fb975910651820fd889d77152562fd4fbcb5db8
This commit is contained in:
Gabriel Wicke 2012-05-17 14:32:56 +02:00
parent b7fd4498a9
commit e2815b516c
3 changed files with 50 additions and 18 deletions

View file

@ -40,7 +40,15 @@ WikiLinkHandler.prototype.onWikiLink = function ( token, frame, cb ) {
// Check if page exists
//
//console.warn( 'title: ' + JSON.stringify( title ) );
var obj = new TagTk( 'a', [ new KV( 'href', title.makeLink() ) ] ),
var obj = new TagTk( 'a',
[
new KV( 'href', title.makeLink() ),
new KV('typeof', 'http://mediawiki.org/rdf/wikilink'),
// Add resource as CURIE- needs global default prefix
// definition.
new KV('resource', '[:' + title.getPrefixedText() + ']')
]
),
content = token.attribs.slice(1, -1);
//console.warn('content: ' + JSON.stringify( content, null, 2 ) );
// XXX: handle trail
@ -254,6 +262,7 @@ WikiLinkHandler.prototype.renderThumb = function ( token, manager, cb, title, pa
new KV('class', figureclass),
new KV('style', figurestyle),
new KV('typeof', 'http://mediawiki.org/rdf/Thumb'),
// XXX: define this globally?
new KV('prefix', "mw: http://mediawiki.org/rdf/terms/")
]
),
@ -272,7 +281,9 @@ WikiLinkHandler.prototype.renderThumb = function ( token, manager, cb, title, pa
//new KV('height', '160px'),
new KV('class', 'thumbimage'),
new KV('alt', oHash.alt || title.key ),
new KV('resource', title.getPrefixedText())
// Add resource as CURIE- needs global default prefix
// definition.
new KV('resource', '[:' + title.getPrefixedText() + ']')
]
),
new EndTagTk( 'a' ),
@ -359,15 +370,22 @@ ExternalLinkHandler.prototype.onUrlLink = function ( token, frame, cb ) {
cb( { tokens: [ new SelfclosingTagTk( 'img',
[
new KV( 'src', href ),
new KV( 'alt', href.split('/').last() )
]
new KV( 'alt', href.split('/').last() ),
new KV('typeof', 'http://mediawiki.org/rdf/externalImage')
],
{ type: 'urllink' }
)
]
} );
} else {
cb( {
tokens: [
new TagTk( 'a', [ new KV( 'href', href ) ] ),
new TagTk( 'a',
[
new KV( 'href', href ),
new KV('typeof', 'http://mediawiki.org/rdf/externalLink')
],
{ type: 'urllink' } ),
href,
new EndTagTk( 'a' )
]
@ -396,7 +414,8 @@ ExternalLinkHandler.prototype.onExtLink = function ( token, manager, cb ) {
[
new KV( 'src', src ),
new KV( 'alt', src.split('/').last() )
] )
],
{ type: 'extlink' })
];
}
@ -405,7 +424,11 @@ ExternalLinkHandler.prototype.onExtLink = function ( token, manager, cb ) {
[
new TagTk ( 'a',
[ new KV('href', href) ],
[
new KV('href', href),
new KV('typeof', 'http://mediawiki.org/rdf/externalLink'),
new KV('property', 'http://mediawiki.org/rdf/terms/linkcontent')
],
token.dataAttribs
)
].concat( content, [ new EndTagTk( 'a' )])

View file

@ -81,6 +81,22 @@ WSP._serializeTableTag = function ( symbol, state, token ) {
}
};
WSP._linkHandler = function( state, token ) {
return '[[';
// TODO: handle internal/external links etc using RDFa and dataAttribs
// Also convert unannotated html links to external wiki links for html
// import. Might want to consider converting relative links without path
// component and file extension to wiki links.
//if ( rtinfo.type === 'wikilink' ) {
// return '[[' + rtinfo.target + ']]';
//} else {
// // external link
// return '[' + rtinfo.
};
WSP._linkEndHandler = function( state, token ) {
return ']]';
};
WSP.tagToWikitext = {
body: {},
b: { start: id("'''"), end: id("'''") },
@ -128,16 +144,8 @@ WSP.tagToWikitext = {
h4: { start: id("\n===="), end: id("====\n") },
h5: { start: id("\n====="), end: id("=====\n") },
h6: { start: id("\n======"), end: id("======\n") },
pre: { start: id("<pre>"), end: id("</pre>") }
/*
a: {
start: function( state, token ) {
if ( rtinfo.type === 'wikilink' ) {
return '[[' + rtinfo.target + ']]';
} else {
// external link
return '[' + rtinfo.
*/
pre: { start: id("<pre>"), end: id("</pre>") },
a: { start: WSP._linkHandler, end: WSP._linkEndHandler }
};

View file

@ -565,7 +565,8 @@ extlink
new SelfclosingTagTk( 'extlink', [
new KV('href', target),
new KV('content', text)
] )
],
{ type: 'extlink' })
];
}
/ "[" & { return stops.pop('extlink'); }