To learn how to do hyperlinking with inter.rb see this.
#!/usr/bin/env ruby
file = ARGV[0];
text = File.open(file,”r”).readlines.join;
urlmap = {“w” => “http://en.wikipedia.org/wiki/%s”,
“g” => “http://google.com/search?q=%s”,
“dict” => “http://m-w.com/dictionary/%s”,
“http” => “http:%s”,
“th” => “http://thesaurus.reference.com/search?q=%s”
}
text.gsub!(/\\[\\[(w+?):(.+?)\\]\\]/) { |match|
path=urlmap[$1]
if path == nil then
puts “%s not found in urlmap” % $1
match
else
str = $2.split(‘|’)
if str.size == 1 then
str %s’) % [str[0], str[1]]
end
}
#puts text
File.open(file, “w”).puts text;
Recent Comments