To support this process, he wrote a small Google:AppleScript for the users of the productivity tool Google:TextExpander.
As AppleScript? doesn't support Regex expressions, he has started to think about using the script language Groovy (a dialect, that creates VM code for Java's Runtime Engine).
He leaves a copy here for community optimization and the original as [GoogleSideWiki] comment.
on WikifyGoogleSideWiki()
(* This alfa AppleScript? WikifyGoogleSidewiki, Version 0.0 loads the ClipBoard? and converts all CamelCase words into links to a chosen Wiki, possibly to WantedWikipages?. The author made it as a scriptlet for TextExpander?. To use it, cut some text with CamelCase words into the clipboard, apply the script and paste the wikified text as a GoogleSideWiki comment. Enjoy it at your own risk. (CC 2009) Share alike with Author credit + allowing derived works + Retweet the author(s) with "RT@fridemar,... Thank your for #WikifyGoogleSideWiki" *)
set wikiprefixes to {"Google:http://google.com/search?q=", "Meatball:http://www.usemod.com/cgi-bin/mb.pl?", "Communitywiki:http://www.communitywiki.org/en/", "Wiki:http://c2.com/cgi/wiki?"}
choose from list wikiprefixes with prompt "Choose a wikiPrefix for expanding CamelCaseWords? in the namespace of that wiki."
set theSelection to result
if theSelection = false then display dialog "The clipboard was not wikified" buttons {"OK"} return else set selectedItem to item 1 of theSelection set wikiprefix to text from ((offset of ":" in selectedItem) + 1) to -1 of selectedItem -- display dialog wikiPrefix -- return end if
considering case set clb to the clipboard as text if clb = "" then exit repeat end if set UpperCaseChars? to "ABCDEFGHIJKLMNOPQRSTUVWXYZ" set LowerCaseChars? to "abcdefghijklmnopqrstuvwxyz" set Digits to "0123456789" set WikiWordChars? to UpperCaseChars? & LowerCaseChars? & Digits
set countClb to (count characters of clb) set i to 1 set currentChar to character i of clb set wikifiedText to ""
repeat while i ≤ countClb
-- a substring before a wikiWord ?
repeat while i ≤ countClb
set possibleWikiWord to "" set CamelCaseCount? to 0 if (currentChar is in UpperCaseChars?) then exit repeat end if set wikifiedText to wikifiedText & currentChar set i to i + 1 if (i > countClb) then exit repeat end if
set currentChar to character i of clb end repeat
-- possible WikiWord ?
repeat while (i ≤ countClb) set possibleWikiWord to possibleWikiWord & currentChar if currentChar is in UpperCaseChars? then set CamelCaseCount? to CamelCaseCount? + 1 end if
set i to i + 1 if (i > countClb) then exit repeat end if set currentChar to character i of clb if not (currentChar is in WikiWordChars?) then if CamelCaseCount? ≥ 2 then set WikiWord to possibleWikiWord set wikifiedText to wikifiedText & "<a href=\"" & wikiprefix & WikiWord & "\">" & WikiWord & "</a>" exit repeat else set noWikiWord to possibleWikiWord set wikifiedText to wikifiedText & noWikiWord exit repeat end if end if end repeat end repeat
display dialog wikifiedText buttons {"OK", "Cancel"} default button {"OK"} if button returned of result = "OK" then set the clipboard to wikifiedText display dialog "The clipboard was set to wikifiedText. You can paste it now. " buttons {"OK"} default button "OK" else display dialog "No wikifiedText in the clipboard" buttons {"OK"} default button "OK" end if end consideringend WikifyGoogleSideWiki
For (Script-) languages like Groovy that natively support Regexes or for editors that offer regular expressions for search and replace, you can use these constructs:
linkifying CamelCase with Google Namespace links
def gUrl = "http:\/\/google.com\/search?q="
str = str.replaceAll(/(\b([A-Z]([a-z0-9?])*){2,}\b)/,/<a href='$gUrl$1'>$1<\/a>/)
linkifying external bracketed links like those used in Meatball
str = str.replaceAll(/\[([-a-zA-Z0-9\/:._&?]+) \b((.+)\b)*?\]/,/<a href=\"$1\">$2<\/a>/)
To declutter Meatball, some additional links are "sidekicked", i.e. outsourced to the accompanyingGoogleSideWiki comment of his section.