Module: HParser::Html

Overview

This module provide to_html method. This method is intended to convert hatena format to html format.

For example:

Hatena::Parser.parse('*foo').to_html # -> <h1>foo</h1>
Hatena::Parser.parse('>|bar|<').to_html # -> <pre>bar</pre>

A class including this module shold implement 2 methods,html_tag and html_content. Obviously,html_tag provid using html tag name. html_content is provid that content. If content is Arary,each elements convert to html by to_html. Otherwise,using as it self.

For example,Head implements is following:

class Hatena::Block::Head
  include Hatena::Html
  def tag_name
    "h#{@level}"
  end

  def content
    @inlines
  end
end

Instance Method Summary collapse

Instance Method Details

#escape(str) ⇒ Object



44
45
46
# File 'lib/hparser/html.rb', line 44

def escape(str)
  CGI.escapeHTML(str)
end

#to_htmlObject



36
37
38
39
40
41
42
# File 'lib/hparser/html.rb', line 36

def to_html
  content = html_content
  if content.class == Array then
    content = content.map{|x| x.to_html}.join
  end
  %(<#{html_tag}>#{content}</#{html_tag}>)
end