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

3 comments:

  1. It seems like you want to do something like chaining commands? if so, this is useful

    http://foyrek.com/chain.html

    ReplyDelete
  2. Good to meet you at SciBlog2008 Egon..they're already labelling next year's event ScienceOnline2009...anyway...

    ...could you tie this script into researchblogging.org so that rather than simply resolving the DOI it also gave users the citation code to add to a blog post about the paper in question?

    ReplyDelete
  3. @Rajarshi: I'll check that...

    @David: great to meet you too! Yeah, saw it. Website was still empty, never too late to grab a domain :)

    Yes, that's basically the same thing... someone did mention that the script does not work for NN, because that does not use HTML for link markup... similarly, for wiki's the markup would look differently... but yes, generally, that should work fine.

    ReplyDelete