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

Allan Odgaard throw-away-1 at macromates.com
Wed Mar 22 16:17:34 UTC 2006


On 22/3/2006, at 16:52, Niko Dittmann wrote:

>> In that case, you could also call iconv -f iso-8859-1 -t utf-8
> certainly right. thank you. this is a shell-command, right? the  
> ruby-method is "iconv", too, i suppose... couldn't figure out how  
> to get this to work... is this used in any other command?

It’s a shell command, yes. Iconv though exist as a library and is  
thus available in a few programming languages as iconv as well.

Using it in Ruby to convert from iso-8859-1 should be a matter of:

    require 'iconv'
    ...
    $html = Iconv.iconv("utf-8", "iso-8859-1", $html)

>> But you could also do something like:
>>
>> puts "<meta http-equiv='Refresh' content='0;URL=#{url}'>"
>> That should then also save you the trouble of rewriting the  
>> relative URLs.
> hm.... but as i include 2 selfhtml-pages (elemtens and attributes)  
> into one page of output i thought it would be a good idea to filter  
> the pages before concating them and just show the documentation for  
> what i lookup... with your method it isn't even possible to include  
> 2 pages into one, is it?

It is not, no. I overlooked that part, sorry.

>> You can also read TM_CURRENT_LINE and TM_LINE_INDEX for the carets  
>> position and search back for the tag in code.
> hmm... i couldn't figure out how to do this. this would be far more  
> elegant. is there another command where this is used?

The CSS -> Documentation for Property does something close, but not  
exactly the same.

Here’s an example which grab the first (when scanning right-to-left)  
tag to the left of the caret:

    line = ENV["TM_CURRENT_LINE"].to_s
    pos  = ENV["TM_LINE_INDEX"].to_i

    if m = /\A.{0,#{pos}}<\s*(\w+)/.match(line) then
      puts "Tag: " + m[1]
    end

The magic is in the regexp. What it does is, first it ensures the  
match starts from the beginning of the line (‘\A’), then it matches  
at most “caret index” characters, and then it matches a tag (‘<\s*(\w 
+)’), putting the name in capture group 1.

Since the range given (‘{0,#{pos}}’) is greedy, it will match as many  
characters as possible, which still allow for a tag to be matched.




More information about the textmate mailing list