Method: Arrow::HTMLTag#to_html

Defined in:
lib/arrow/htmltokenizer.rb

#to_htmlObject

Return an HTML fragment that can be used to represent the token symbolically in a web-based introspection interface.



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/arrow/htmltokenizer.rb', line 276

def to_html
  tagopen, tagbody = @raw.split( /\s+/, 2 )
  # self.log.debug "tagopen = %p, tagbody = %p" % [ tagopen, tagbody ]

  tagopen = self.escape_html( tagopen ).sub( %r{^<(/)?(\w+)} ) {|match|
    %Q{&lt;#$1<span class="tag-token-name">#$2</span>}
  }

  unless tagbody.nil?
    tagbody.sub!( />$/, '' )
    tagbody = self.escape_html( tagbody ).gsub( AttributePattern ) {|match|
      name, mid, val = match.split(/(\s*=\s*)/, 2)

      val.gsub!( /(\[\?(?:[^\?]|\?(?!\]))+\?\])/s ) {|m|
        %q{<span class="%s">%s</span>} %
          [ 'tag-attr-directive', m ]
      }

      %q{<span class="%s">%s</span>%s<span class="%s">%s</span>} % [
        'tag-token-attr-name',
        name,
        mid,
        'tag-token-attr-value',
        val,
      ]
    }
    tagbody << '&gt;'
  end

  #self.log.debug "tagopen = %p; tagbody = %p" %
  #  [ tagopen, tagbody ]
  super { [tagopen, tagbody].compact.join(" ") }
end