Skip to content

Instantly share code, notes, and snippets.

@erickedji
Created April 9, 2009 21:12
Show Gist options
  • Select an option

  • Save erickedji/92741 to your computer and use it in GitHub Desktop.

Select an option

Save erickedji/92741 to your computer and use it in GitHub Desktop.
ubiquity: turn all urls in the selection into links
/*
* Turn all urls in the selection into links
* Frustrated by Google docs asking me to do CTRL-K, ENTER for every link.
* Eric KEDJI <eric.kedji@gmail.com>
*/
CmdUtils.CreateCommand({
name: "linkify",
homepage: "http://erickedji.wordpress.com/",
author: {name: "Eric", email: "eric.kedji@gmail.com"},
license: "GPL",
description: "Turn all the urls in the selection into links",
help: "Invoke it on a chunk of text",
takes: {"input": /.*/},
preview: function(pblock, input) {
pblock.innerHTML = "'Linkify' the selected text.";
},
execute: function(input) {
CmdUtils.setSelection(
input.text.replace(/http:\/\/([^ \)]+)/g, '<a href="http:\/\/$1">http:\/\/$1</a>'));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment