[TxMt] HTML: lookup element-reference on de.selfhtml.org

Niko Dittmann ni-di at web.de
Wed Mar 22 12:12:18 UTC 2006


for all the germans using textmate for html-coding this little  
command will lookup the current html-element on selfhtml.org. i'm  
sorry as of now there's no english version of this excellent website  
available.

regards, niko.


#!/usr/bin/env ruby
#
# open element reference on de.selfhtml.org
# this is certainly a BAD implementation
# works for me, though
# any improvements are highly appreciated
# niko.

require 'net/http'
$tag_name = ENV["TM_CURRENT_WORD"].to_s

# 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')

# output the html
puts $html


-- 
____________________________
niko dittmann <ni-di at web.de>
____________________________



More information about the textmate mailing list