Sha256: 0a155f860dcf4cd38f894253594f3c1e3862a7f20a3afcb34e495acfabd83507

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

module Coradoc
  module Element
    class ListItem < Base
      attr_accessor :marker, :id, :anchor, :content, :line_break

      declare_children :content, :id, :anchor

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

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

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

        " #{anchor}#{content.chomp}#{@line_break}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coradoc-1.1.3 lib/coradoc/element/list_item.rb
coradoc-1.1.2 lib/coradoc/element/list_item.rb
coradoc-1.1.1 lib/coradoc/element/list_item.rb