Class: Minidown::ParagraphElement
- Defined in:
- lib/minidown/elements/paragraph_element.rb
Constant Summary collapse
- ExcludeSchemeRegexp =
/\A[^@:]+\z/
- StringSymbolRegexp =
/"|'/
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#extra ⇒ Object
Returns the value of attribute extra.
Attributes inherited from Element
#children, #content, #doc, #nodes
Instance Method Summary collapse
-
#initialize(*_) ⇒ ParagraphElement
constructor
A new instance of ParagraphElement.
- #parse ⇒ Object
- #text ⇒ Object
- #to_html ⇒ Object
Methods inherited from Element
#blank?, #raw_content, #raw_content=, #unparsed_lines
Methods included from HtmlHelper
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
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
3 4 5 |
# File 'lib/minidown/elements/paragraph_element.rb', line 3 def contents @contents end |
#extra ⇒ Object
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
#parse ⇒ Object
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 |
#text ⇒ Object
23 24 25 |
# File 'lib/minidown/elements/paragraph_element.rb', line 23 def text build_element raw_content end |
#to_html ⇒ Object
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 |