Module: HParser::Html
- Included in:
- Block::Dl, Block::Head, Block::P, Block::Pre, Block::Quote, Block::Quote::QuoteUrl, Block::SuperPre, Block::TableCell, Block::TableHeader, Inline::Url
- Defined in:
- lib/hparser/html.rb
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
Constant Summary collapse
- ESCAPE_TABLE =
{ '&' => '&', '"' => '"', '<' => '<', '>' => '>' }
Instance Method Summary collapse
Instance Method Details
#escape(str) ⇒ Object
49 50 51 |
# File 'lib/hparser/html.rb', line 49 def escape(str) str.gsub(/[&"<>]/n) {|c| ESCAPE_TABLE[c] } end |
#to_html ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/hparser/html.rb', line 34 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 |