Class: Coradoc::Element::ListItem

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/element/list_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

children_accessors, #children_accessors, declare_children, #simplify_block_content, visit, #visit

Constructor Details

#initialize(content, options = {}) ⇒ ListItem

Returns a new instance of ListItem.



8
9
10
11
12
# File 'lib/coradoc/element/list_item.rb', line 8

def initialize(content, options = {})
  @content = content
  @id = options.fetch(:id, nil)
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
end

Instance Attribute Details

#anchorObject

Returns the value of attribute anchor.



4
5
6
# File 'lib/coradoc/element/list_item.rb', line 4

def anchor
  @anchor
end

#contentObject

Returns the value of attribute content.



4
5
6
# File 'lib/coradoc/element/list_item.rb', line 4

def content
  @content
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/coradoc/element/list_item.rb', line 4

def id
  @id
end

Instance Method Details

#to_adocObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/coradoc/element/list_item.rb', line 14

def to_adoc
  anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s
  content = Array(@content).map do |subitem|
    next if subitem.is_a? Coradoc::Element::Inline::HardLineBreak

    subcontent = Coradoc::Generator.gen_adoc(subitem)
    # Only try to postprocess elements that are text,
    # otherwise we could strip markup.
    if Coradoc.is_a_single?(subitem, Coradoc::Element::TextElement)
      subcontent = Coradoc.strip_unicode(subcontent)
    end
    subcontent.chomp
  end.compact.join("\n+\n")

  " #{anchor}#{content.chomp}\n"
end