def render
@lines = []
@context = []
Parser::each_token(@source) do |token, data, attributes|
case token
when :TEXT
if @context[-1] == :in_pre
tmp = data.split("\n", -1)
if @lines[-1]
@lines[-1] << tmp.shift
end
@lines += tmp
else
reflow_text(data)
end
when :START_TAG
@current_attributes = attributes
tag = TAG_SET[data]
next unless tag
context_enter(@context, tag)
call_actions(tag, :start)
when :END_TAG
tag = TAG_SET[data]
next unless tag
context_exit(@context, tag)
call_actions(tag, :end)
end
end
until @lines[-1] != ''
@lines.delete_at(@lines.size - 1)
end
unless @links.empty?
@lines << ''
@lines << $config['msg_links']
padding = @links.size / 10 + 1
@links.each_with_index do |link, index|
@lines << "%#{padding}d. %s" % [index + 1, link]
end
end
unless @images.empty?
@lines << ''
@lines << $config['msg_images']
padding = @images.size / 10 + 1
@images.each_with_index do |image,index|
@lines << "%#{padding}d. %s" % [index + 1,image]
end
end
rendered_text = @lines.join("\n") + "\n"
$config['unescape_html'] ? rendered_text.unescape_html : rendered_text
end