Class: HParser::Block::Head

Inherits:
Object
  • Object
show all
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

Constants included from Html

Html::ESCAPE_TABLE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hatena

#to_hatena

Methods included from Text

#to_text

Methods included from Html

#escape, #to_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

#contentObject (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

#levelObject (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_levelObject



83
84
85
# File 'lib/hparser/html.rb', line 83

def self.head_level
  @@head_level
end

.head_level=(l) ⇒ Object



80
81
82
# File 'lib/hparser/html.rb', line 80

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_latexObject



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