Class: ODDB::BasicHtmlParser

Inherits:
HTMLParser
  • Object
show all
Defined in:
src/util/html_parser.rb

Direct Known Subclasses

ChapterParse::Parser, HtmlParser

Constant Summary

Entitydefs =
entities

Instance Method Summary (collapse)

Instance Method Details

- (Object) end_table



47
48
49
# File 'src/util/html_parser.rb', line 47

def end_table
  @formatter.pop_table
end

- (Object) end_td



50
51
52
53
# File 'src/util/html_parser.rb', line 50

def end_td
  @formatter.pop_alignment
  @formatter.pop_tablecell
end

- (Object) end_tr



54
55
56
# File 'src/util/html_parser.rb', line 54

def end_tr
  @formatter.pop_tablerow
end

- (Object) finish_endtag(tag)



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'src/util/html_parser.rb', line 57

def finish_endtag(tag)
  if tag == ''
    found = @stack.length - 1
    if found < 0
      unknown_endtag(tag)
      return
    end
  else
    unless @stack.include? tag
      method = 'end_' + tag
      unless self.respond_to?(method)
        unknown_endtag(tag)
      end
      return
    end
    found = @stack.rindex(tag) #or @stack.length
  end
  if(@stack.last == 'pre')
    if(tag == 'pre')
      handle_endtag(tag, :end_pre)
      @stack.pop
    end
  else
    while @stack.length > found
      tag = @stack[-1]
      method = 'end_' + tag
      if respond_to?(method)
        handle_endtag(tag, method)
      else
        unknown_endtag(tag)
      end
      @stack.pop
    end
  end
end

- (Object) start_table(attrs)



97
98
99
# File 'src/util/html_parser.rb', line 97

def start_table(attrs)
  @formatter.push_table(attrs)
end

- (Object) start_td(attrs)



100
101
102
103
104
105
106
107
# File 'src/util/html_parser.rb', line 100

def start_td(attrs)
  align = attrs.collect { |key, val| 
    val if(key == 'align')
  }.compact.last
  align = align.downcase if(align.is_a? String)
  @formatter.push_alignment(align)
  @formatter.push_tablecell(attrs)
end

- (Object) start_tr(attrs)



108
109
110
# File 'src/util/html_parser.rb', line 108

def start_tr(attrs)
  @formatter.push_tablerow(attrs)
end

- (Object) unknown_entityref(name)



92
93
94
95
96
# File 'src/util/html_parser.rb', line 92

def unknown_entityref(name)
  if(data = self::class::Entitydefs[name])
    handle_data(data)
  end
end