Class: HParser::Block::Dl

Inherits:
Object
  • Object
show all
Includes:
Collectable, Html, Latex
Defined in:
lib/hparser/html.rb,
lib/hparser/text.rb,
lib/hparser/latex.rb,
lib/hparser/block/dl.rb

Defined Under Namespace

Classes: Item

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Html

#escape, #to_html

Constructor Details

#initialize(*items) ⇒ Dl

Returns a new instance of Dl.



36
37
38
# File 'lib/hparser/block/dl.rb', line 36

def initialize(*items)
  @items = items
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



35
36
37
# File 'lib/hparser/block/dl.rb', line 35

def items
  @items
end

Class Method Details

.parse(scanner, context, inlines) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/hparser/block/dl.rb', line 24

def self.parse(scanner,context,inlines)
  items = []
  while scanner.scan(/\A:((?:<[^>]+>|\[[^\]]+\]|[^:])+):(.+)/)
    i = scanner.matched.index(':',1)
    title = inlines.parse scanner.matched_pattern[1], context
    description = inlines.parse scanner.matched_pattern[2], context
    items.push Item.new(title,description)
  end
  items == [] ? nil : self.new(*items)
end

Instance Method Details

#==(o) ⇒ Object



40
41
42
# File 'lib/hparser/block/dl.rb', line 40

def ==(o)
  o.class == self.class and o.items == self.items
end

#html_contentObject



213
214
215
# File 'lib/hparser/html.rb', line 213

def html_content
  @items
end

#html_tagObject



209
210
211
# File 'lib/hparser/html.rb', line 209

def html_tag() 
  'dl' 
end

#latex_contentObject



155
156
157
# File 'lib/hparser/latex.rb', line 155

def latex_content
  @items
end

#to_latexObject



150
151
152
153
# File 'lib/hparser/latex.rb', line 150

def to_latex
  content = super
  %Q[\\begin{description}\n#{content}\n\\end{description}\n]
end

#to_textObject



106
107
108
# File 'lib/hparser/text.rb', line 106

def to_text
  @items.map{|x| x.to_text}.join("\n")
end