Class: HParser::Block::Head
- Inherits:
-
Object
- Object
- HParser::Block::Head
- Includes:
- Collectable, Hatena, Html, Latex, Text
- Defined in:
- lib/hparser/block/head.rb,
lib/hparser/html.rb,
lib/hparser/text.rb,
lib/hparser/latex.rb,
lib/hparser/hatena.rb
Overview
Header parser.
Header is defiend as “a line which is start with ‘*’”. And a number of ‘*’ show that level.
For example:
* level1
** level2
*** level3
Constant Summary collapse
- @@head_level =
1
Instance Attribute Summary collapse
-
#content ⇒ Object
(also: #html_content, #text_content, #latex_content)
readonly
Returns the value of attribute content.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Class Method Summary collapse
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#initialize(level, content) ⇒ Head
constructor
A new instance of Head.
- #to_latex ⇒ Object
Methods included from Hatena
Methods included from Text
Methods included from Html
Constructor Details
#initialize(level, content) ⇒ Head
Returns a new instance of Head.
34 35 36 37 |
# File 'lib/hparser/block/head.rb', line 34 def initialize(level,content) @level = level @content = content end |
Instance Attribute Details
#content ⇒ Object (readonly) Also known as: html_content, text_content, latex_content
Returns the value of attribute content.
33 34 35 |
# File 'lib/hparser/block/head.rb', line 33 def content @content end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
33 34 35 |
# File 'lib/hparser/block/head.rb', line 33 def level @level end |
Class Method Details
.head_level ⇒ Object
78 79 80 |
# File 'lib/hparser/html.rb', line 78 def self.head_level @@head_level end |
.head_level=(l) ⇒ Object
75 76 77 |
# File 'lib/hparser/html.rb', line 75 def self.head_level=(l) @@head_level = l end |
.parse(scanner, context, inlines) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hparser/block/head.rb', line 19 def self.parse(scanner,context,inlines) if scanner.scan(/\A\*/) then level = 0 scanner.matched.each_byte{|c| if c.chr == '*' then level += 1 else break end } Head.new level,inlines.parse(scanner.matched[level..-1].strip, context) end end |
Instance Method Details
#==(o) ⇒ Object
39 40 41 42 |
# File 'lib/hparser/block/head.rb', line 39 def ==(o) o.class == self.class and o.level == self.level and o.content == self.content end |
#to_latex ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hparser/latex.rb', line 35 def to_latex content = super headers = [ nil, "section", "subsection", "subsubsection", "paragraph", "subparagraph", "textbf" ] level = @@head_level + self.level - 1 "\\#{headers[level]}{#{content}}\n\n" end |