diff --git a/modules/parser/ext.core.LinkHandler.js b/modules/parser/ext.core.LinkHandler.js index e9b637916c..ad39dbe3c0 100644 --- a/modules/parser/ext.core.LinkHandler.js +++ b/modules/parser/ext.core.LinkHandler.js @@ -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' )]) diff --git a/modules/parser/mediawiki.WikitextSerializer.js b/modules/parser/mediawiki.WikitextSerializer.js index b442b0b4e4..7893c2efce 100644 --- a/modules/parser/mediawiki.WikitextSerializer.js +++ b/modules/parser/mediawiki.WikitextSerializer.js @@ -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("
"), end: id("") } - /* - a: { - start: function( state, token ) { - if ( rtinfo.type === 'wikilink' ) { - return '[[' + rtinfo.target + ']]'; - } else { - // external link - return '[' + rtinfo. - */ + pre: { start: id("
"), end: id("") }, + a: { start: WSP._linkHandler, end: WSP._linkEndHandler } }; diff --git a/modules/parser/pegTokenizer.pegjs.txt b/modules/parser/pegTokenizer.pegjs.txt index 36d6dd6fff..c9c4e0da75 100644 --- a/modules/parser/pegTokenizer.pegjs.txt +++ b/modules/parser/pegTokenizer.pegjs.txt @@ -565,7 +565,8 @@ extlink new SelfclosingTagTk( 'extlink', [ new KV('href', target), new KV('content', text) - ] ) + ], + { type: 'extlink' }) ]; } / "[" & { return stops.pop('extlink'); }