Class: Minidown::BlockElement

Inherits:
Element
  • Object
show all
Defined in:
lib/minidown/elements/block_element.rb

Constant Summary collapse

BlockTagRegexp =
/\A\s*\>\s*/

Instance Attribute Summary

Attributes inherited from Element

#children, #content, #doc, #nodes

Instance Method Summary collapse

Methods inherited from Element

#blank?, #initialize, #raw_content, #raw_content=, #unparsed_lines

Methods included from HtmlHelper

#br_tag, #build_tag

Constructor Details

This class inherits a constructor from Minidown::Element

Instance Method Details

#parseObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/minidown/elements/block_element.rb', line 5

def parse
  unparsed_lines.unshift content
  nodes << self
  while(child_line = unparsed_lines.shift) do
    block = child_line.sub! BlockTagRegexp, ''
    doc.parse_line(child_line)
    child = nodes.pop
    case child
    when LineElement
      unparsed_lines.unshift child_line
      unparsed_lines.unshift nil
    when ParagraphElement
      child.extra = !!block
      nodes << child
    else
      break if child.nil?
      nodes << child 
    end
  end
  children_range = (nodes.index(self) + 1)..-1
  self.children = nodes[children_range]
  nodes[children_range] = []
end

#to_htmlObject



29
30
31
32
33
34
35
# File 'lib/minidown/elements/block_element.rb', line 29

def to_html
  build_tag 'blockquote'.freeze do |content|
    children.each do |child|
      content << child.to_html
    end
  end
end