Skip to content

Instantly share code, notes, and snippets.

@tothda
Created September 9, 2008 22:23
Show Gist options
  • Select an option

  • Save tothda/9783 to your computer and use it in GitHub Desktop.

Select an option

Save tothda/9783 to your computer and use it in GitHub Desktop.
// Slightly modified version of the official syntax-highlight command. The original does not work for me with Ruby.
// it uses: http://xzfv.appspot.com
// ruby formatting only
CmdUtils.CreateCommand({
name: "shl",
takes: {"code": noun_arb_text},
icon: "chrome://ubiquity/skin/icons/color_wheel.png",
description: "Treats your selection as program source code, guesses its language, and colors it based on syntax.",
execute: function( directObj ) {
var code = directObj.text;
var url = "http://xzfv.appspot.com/doformat";
var params = {
source: code,
language: "ruby",
output: "html"
};
jQuery.ajax({
type: 'POST',
url: url,
data: params,
success: function( data ) {
var tempElement = CmdUtils.getHiddenWindow().document.createElementNS("http://www.w3.org/1999/xhtml", "div");
tempElement.innerHTML = data;
var html = jQuery(tempElement).find('.highlight').html();
CmdUtils.setSelection(html);
}
});
},
preview: "Syntax highlights your code."
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment