Class: Minidown::ParagraphElement

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

Constant Summary collapse

ExcludeSchemeRegexp =
/\A[^@:]+\z/
StringSymbolRegexp =
/"|'/

Instance Attribute Summary collapse

Attributes inherited from Element

#children, #content, #doc, #nodes

Instance Method Summary collapse

Methods inherited from Element

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

Methods included from HtmlHelper

#br_tag, #build_tag

Constructor Details

#initialize(*_) ⇒ ParagraphElement

Returns a new instance of ParagraphElement.



9
10
11
12
13
# File 'lib/minidown/elements/paragraph_element.rb', line 9

def initialize *_
  super
  @contents = [raw_content]
  @extra = false
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



3
4
5
# File 'lib/minidown/elements/paragraph_element.rb', line 3

def contents
  @contents
end

#extraObject

Returns the value of attribute extra.



4
5
6
# File 'lib/minidown/elements/paragraph_element.rb', line 4

def extra
  @extra
end

Instance Method Details

#parseObject



15
16
17
18
19
20
21
# File 'lib/minidown/elements/paragraph_element.rb', line 15

def parse
  if ParagraphElement === nodes.last
    nodes.last.contents << raw_content
  else
    nodes << self
  end
end

#textObject



23
24
25
# File 'lib/minidown/elements/paragraph_element.rb', line 23

def text
  build_element raw_content
end

#to_htmlObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/minidown/elements/paragraph_element.rb', line 27

def to_html
  if @extra
    contents.map{|content| ParagraphElement.new(doc, content).to_html }.join ''.freeze
  else
    contents.map! do |line|
      build_element line
    end
    build_tag 'p'.freeze do |content|
      pre_elem = contents.shift
      content << pre_elem.to_html
      while elem = contents.shift
        content << br_tag if TextElement === pre_elem && TextElement === elem
        content << elem.to_html
        pre_elem = elem
      end
    end
  end
end