Pages

Monday, September 01, 2008

Ubiquity fun: resolving DOIs

Now, I'm really after something else, but here's my first Ubiquity scripts. It allow you to select a DOI on any web page (which really only makes sense if it is not already a hyperlink), you hit ALT-SPACE (Linux), CTRL-SPACE (Windows), or whatever the shortcut is on your operating system, and type resolve-doi and it will automatically convert the DOI into a hyperlink to look up the paper.

What I am actually interested in, is being able to use this command in a blog editing environment; however, I have not managed to get that working in one command. And because I am apparently not able to put in two ubiquity commands in blog items, you need to go to this page.

Second warning. I have only tried them with Ubiquity 0.1, not 0.1.1, or even later.

For the curious, the script looks like:
CmdUtils.CreateCommand({
name: "resolve-doi",
homepage: "http://chem-bla-ics.blogspot.com/",
author: { name: "Egon Willighagen", email: "egon.willighagen@gmail.com"},
description: "Resolves a DOI into a URL",
license: "GPL",
takes: {"doi": noun_arb_text},

preview: function( pblock, doi ) {
var msg = 'Inserts a URL for the DOI: ${doi}';
var d = doi.text || CmdUtils.getSelection();
pblock.innerHTML = CmdUtils.renderTemplate(msg, {doi: d});
},

execute: function( doi ) {
var msg = '<a href="http://dx.doi.org/${doi}">${doi}</a>';
var d = doi.text || CmdUtils.getSelection();
var newText = CmdUtils.renderTemplate(msg, {doi: d});
CmdUtils.setSelection(newText);
}
})
Comments on this code most welcome! It's GPL. Details can be found in this tutorial and examples in Rajarshi's blog