Sha256: 8c22cba74c5f9fee91396a65d04519403389515072d3b54b47415df06b79d07f
Contents?: true
Size: 1.87 KB
Versions: 1
Compression:
Stored size: 1.87 KB
Contents
module Asciidoctor # Public: Methods for managing items for AsciiDoc olists, ulist, and dlists. class ListItem < AbstractBlock # Public: Get/Set the String used to mark this list item attr_accessor :marker # Public: Initialize an Asciidoctor::ListItem object. # # parent - The parent list block for this list item # text - the String text (default nil) def initialize(parent, text = nil) super(parent, :list_item) @text = text @level = parent.level end def text? !@text.to_s.empty? end def text # this will allow the text to be processed Block.new(self, nil, [@text]).content end def content blocks? ? blocks.map {|b| b.render }.join : nil end # Public: Fold the first paragraph block into the text # # Here are the rules for when a folding occurs: # # Given: this list item has at least one block # When: the first block is a paragraph that's not connected by a list continuation # Or: the first block is an indented paragraph that's adjacent (wrapped line) # Or: the first block is an indented paragraph that's not connected by a list continuation # Then: then drop the first block and fold it's content (buffer) into the list text # # Returns nothing def fold_first(continuation_connects_first_block = false, content_adjacent = false) if !blocks.empty? && blocks.first.is_a?(Block) && ((blocks.first.context == :paragraph && !continuation_connects_first_block) || ((content_adjacent || !continuation_connects_first_block) && blocks.first.context == :literal && blocks.first.attr('options', []).include?('listparagraph'))) block = blocks.shift unless @text.to_s.empty? block.buffer.unshift("#@text\n") end @text = block.buffer.join end nil end def to_s "#{super.to_s} - #@context [text:#@text, blocks:#{(@blocks || []).size}]" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
asciidoctor-0.1.3 | lib/asciidoctor/list_item.rb |