CmdUtils.CreateCommand({ names: ["mdlink", "markdown link"], arguments: [{role: "object", nountype: noun_arb_text, label: "search term"}], preview: "Replaces the selected text with a Markdown link to the first Google result for that text.", execute: function( args ) { var baseUrl = "http://ajax.googleapis.com/ajax/services/search/web"; var params = {v: "1.0", q: args.object.text}; jQuery.getJSON( baseUrl, params, function( results ) { CmdUtils.setSelection( "[" + args.object.text + "](" + results.responseData.results[0].url + ")" ); }) } });