Skip to content

Instantly share code, notes, and snippets.

@erickedji
Created April 8, 2009 23:57
Show Gist options
  • Save erickedji/92140 to your computer and use it in GitHub Desktop.
Save erickedji/92140 to your computer and use it in GitHub Desktop.
ubiquity: syntax-highlight selection
/*
* Syntax-highlighting verb for Ubiquity, using the online service at
* quickhighlighter.com.
* Eric KEDJI <eric.kedji@gmail.com>
*/
noun_type_programmingLanguage = new CmdUtils.NounType( "Programming language",
['abap', 'actionscript', 'actionscript3', 'ada', 'apache', 'applescript', 'asm', 'asp', 'autoit', 'bash', 'basic4gl', 'blitzbasic', 'bnf', 'c', 'c_mac', 'caddcl', 'cadlisp', 'cfdg', 'cfm', 'cpp', 'cpp-qt', 'csharp', 'css', 'd', 'delphi', 'diff', 'div', 'dos', 'dot', 'eiffel', 'fortran', 'freebasic', 'genero', 'gettext', 'glsl', 'gml', 'groovy', 'haskell', 'html4strict', 'idl', 'ini', 'inno', 'io', 'java', 'java5', 'javascript', 'kixtart', 'latex', 'lisp', 'lotusformulas', 'lotusscript', 'lua', 'm68k', 'matlab', 'mirc', 'mpasm', 'mxml', 'mysql', 'nsis', 'objc', 'ocaml', 'ocaml-brief', 'oobas', 'oracle8', 'pascal', 'per', 'perl', 'php', 'php-brief', 'plsql', 'python', 'qbasic', 'rails', 'reg', 'robots', 'ruby', 'sas', 'scala', 'scheme', 'sdlbasic', 'smalltalk', 'smarty', 'sql', 'tcl', 'text', 'thinbasic', 'tsql', 'vb', 'vbnet', 'verilog', 'vhdl', 'visualfoxpro', 'winbatch', 'xml', 'xpp', 'z80']);
noun_type_lineNumberOptions = new CmdUtils.NounType( "Line number option",
["none","normal","fancy"]);
noun_type_tabSize = new CmdUtils.NounType( "Tab size",
["2","4","6","8"]);
CmdUtils.CreateCommand({
name: "shighlight",
author: {name: "Eric", email: "eric.kedji@gmail.com"},
homepage: "http://erickedji.wordpress.com/",
license: "GPL",
description: "Highlight a code fragment",
help: "Just invoke it on the selected code, optionnaly with modifiers (see preview)",
takes: {"input": /.*/},
modifiers: {
"as": noun_type_programmingLanguage,
"num": noun_type_lineNumberOptions,
"tab": noun_type_tabSize},
preview: function(pblock, input) {
pblock.innerHTML = "Highlight your selection. Customize with: as (language), num (line number style: none|normal|fancy), tab (tab size: 2|4|6|8)";
},
execute: function(theInput, theMods) {
var url = 'http://quickhighlighter.com/code-syntax-highlighter.php';
var lang = theMods.as.text || "c";
var num = theMods.num.text || "none";
var tabWidth = theMods.tab.text || 4;
var lineNumbersOptions = {"none":0, "normal":1, "fancy":2};
var options = {
language: lang,
line_numbers: lineNumbersOptions[num],
word_wrap: 'true',
tab_width: tabWidth,
selfcontained: 'true',
highlight_keywords: 'on',
source: theInput.text,
default_color: '000099',
submit: 'Highlight!'
};
jQuery.post(url, options, function (html) {
var highlightedCode = jQuery('div[class=' + lang + ']', jQuery(html)).html();
CmdUtils.setSelection('<p style="padding: .5em; border: 1px #ccc solid; line-height:1.2em; font-family:monospace; -moz-border-radius: 3px;">' + highlightedCode + '</p>');
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment