<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">1. open markdown document</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">2. select a word, say “multivariate”</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">2. Select Lookup Word / Selection on Wikipedia and link</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><br class=""></span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">EXPECTED: link to wikipedia wrapped about the selection</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">OBTAINED: Command error</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><br class=""></span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">/Users/tim/Library/Application Support/TextMate/Ruby/1.8.7/lib/ruby/1.8/net/http.rb:586:in `connect': SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: tlsv1 alert protocol version (OpenSSL::SSL::SSLError)</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>from /Users/tim/Library/Application Support/TextMate/Ruby/1.8.7/lib/ruby/1.8/net/http.rb:586:in `connect'</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>from /Users/tim/Library/Application Support/TextMate/Ruby/1.8.7/lib/ruby/1.8/net/http.rb:553:in `do_start'</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>from /Users/tim/Library/Application Support/TextMate/Ruby/1.8.7/lib/ruby/1.8/net/http.rb:542:in `start'</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>from /Users/tim/Library/Application Support/TextMate/Ruby/1.8.7/lib/ruby/1.8/open-uri.rb:242:in `open_http'</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>from /Users/tim/Library/Application Support/TextMate/Ruby/1.8.7/lib/ruby/1.8/open-uri.rb:616:in `buffer_open'</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>from /Users/tim/Library/Application Support/TextMate/Ruby/1.8.7/lib/ruby/1.8/open-uri.rb:164:in `open_loop'</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>from /Users/tim/Library/Application Support/TextMate/Ruby/1.8.7/lib/ruby/1.8/open-uri.rb:162:in `catch'</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>from /Users/tim/Library/Application Support/TextMate/Ruby/1.8.7/lib/ruby/1.8/open-uri.rb:162:in `open_loop'</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>from /Users/tim/Library/Application Support/TextMate/Ruby/1.8.7/lib/ruby/1.8/open-uri.rb:132:in `open_uri'</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>from /Users/tim/Library/Application Support/TextMate/Ruby/1.8.7/lib/ruby/1.8/open-uri.rb:518:in `open'</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>from /Users/tim/Library/Application Support/TextMate/Ruby/1.8.7/lib/ruby/1.8/open-uri.rb:30:in `open'</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>from Lookup Selection on Wikipedia and link:19:in `getWikiEntries'</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>from Lookup Selection on Wikipedia and link:31:in `getWikiDef'</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>from Lookup Selection on Wikipedia and link:37</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><br class=""></span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><br class=""></span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><br class=""></span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">The command is:</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><br class=""></span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Helvetica Neue" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">#!/usr/bin/env ruby18</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">require "#{ENV['TM_SUPPORT_PATH']}/lib/progress.rb"</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes.rb"</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">require "#{ENV['TM_SUPPORT_PATH']}/lib/ui.rb"</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">require 'cgi'</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">require 'open-uri'</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">require 'erb'</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">require 'rexml/document'</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">def select_link(links)</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> linklist = links.map { |p| p['Text'] }</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> item = TextMate::UI.request_item :title => "Multiple Definitions", :prompt => "Please select a definition", :items => linklist</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> TextMate.exit_discard if item.nil?</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> return links[linklist.index(item)]</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">end # select_link</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">def getWikiEntries(phrase)</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> res = []</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> response = open("<a href="https://en.wikipedia.org/w/api.php?format=xml&action=opensearch&search=#{CGI.escape(phrase)}" class="">https://en.wikipedia.org/w/api.php?format=xml&action=opensearch&search=#{CGI.escape(phrase)}</a>", "User-Agent" => "TextMate 2.0")</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> doc = REXML::Document.new(response.read)</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> doc.elements.each('SearchSuggestion/Section/Item') do |item|</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> hash = { }</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> %w[ Text Url Description ].each { |tag| item.elements.each(tag) { |inner| hash[tag] = inner.text } }</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> res << hash</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> end</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> res.sort { |a, b| a['Text'].downcase <=> b['Text'].downcase }</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">end</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">def getWikiDef(phrase)</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> entries = getWikiEntries(phrase)</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> TextMate.exit_show_tool_tip "No definition found" if entries.empty?</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> entry = entries.size > 1 ? select_link(entries) : entries.first</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""> return entry['Url'], "Wikipedia Entry: #{entry['Text']}", phrase</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">end</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">url, title, input = getWikiDef(STDIN.read)</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class="">print ERB.new(ENV['TM_LINK_FORMAT']).result</span></div><div style="caret-color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85); font-size: 11px;" class=""><br class=""></div></font></div></div></div></body></html>