ok. so here's the final result... errm... result... thanks for the help, allan.
niko.
#!/usr/bin/env ruby # # open element + attribute reference on de.selfhtml.org # # idea: niko dittmann # credits for assisting a complete nube go to # allan odgaard (as always) and stan (soryu) # # i guess, theres still some regex-magic to # be improved (as always :)
require 'iconv' require 'net/http'
line = ENV["TM_CURRENT_LINE"].to_s pos = ENV["TM_LINE_INDEX"].to_i
# this regex gets the first tag left of the caret if m = /\A.{0,#{pos}}<\s*(\w+)/.match(line) then $tag_name = m[1] end
# get the elemnte.htm and attribute.htm: Net::HTTP.start( 'de.selfhtml.org', 80 ) do |http| $html_elemente = http.get( "/html/referenz/elemente.htm" ).body $html_attribute = http.get( "/html/referenz/attribute.htm" ).body end
# strip the head and the current tag: $html_elemente.gsub!(/(<!.*<body>).*(<h2><a class="an" name="# {$tag_name}">#{$tag_name}</a></h2>.*?)<h2>.*/m,'\1\2')
# prepend "elemente.htm" to anchor-links: $html_elemente.gsub!(/href="#(.*?")/,'href="elemente.htm#\1')
# the current tag: $html_attribute.gsub!(/.*(<h2><a class="an" name="#{$tag_name}"># {$tag_name}</a></h2>.*?)<h2>.*/m,'\1')
# prepend "elemente.htm" to anchor-links: $html_attribute.gsub!(/href="#(.*?")/,'href="attribute.htm#\1')
# concat the two strings: $html = $html_elemente + $html_attribute
# turn relative links into absolute links (for hrefs and imgs): $html.gsub!(/href="(.*?")/,'href="http://de.selfhtml.org/html/ referenz/\1') $html.gsub!(/src="(.*?")/,'src="http://de.selfhtml.org/html/referenz/ \1')
$html = Iconv.iconv("utf-8", "iso-8859-1", $html) puts $html