class Asciidoctor::ListItem
Public: Methods for managing items for AsciiDoc olists, ulist, and dlists.
Attributes
Public: Get/Set the String used to mark this list item
Public Class Methods
Public: Initialize an Asciidoctor::ListItem object.
parent - The parent list block for this list item text - the String text (default nil)
# File lib/asciidoctor/list.rb, line 55 def initialize parent, text = nil super parent, :list_item @text = text @level = parent.level @subs = NORMAL_SUBS.dup end
Public Instance Methods
Check whether this list item has compound content (nested blocks aside from a single outline list). Primarily relevant for outline lists.
Return true if the list item contains blocks other than a single outline list. Otherwise, return false.
# File lib/asciidoctor/list.rb, line 97 def compound? !simple? 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
# File lib/asciidoctor/list.rb, line 112 def fold_first(continuation_connects_first_block = false, content_adjacent = false) if (first_block = @blocks[0]) && Block === first_block && ((first_block.context == :paragraph && !continuation_connects_first_block) || ((content_adjacent || !continuation_connects_first_block) && first_block.context == :literal && first_block.option?('listparagraph'))) block = blocks.shift block.lines.unshift @text unless @text.nil_or_empty? @text = block.source end nil end
Check whether this list item has simple content (no nested blocks aside from a single outline list). Primarily relevant for outline lists.
Return true if the list item contains no blocks or it contains a single outline list. Otherwise, return false.
# File lib/asciidoctor/list.rb, line 89 def simple? @blocks.empty? || (@blocks.size == 1 && List === (blk = @blocks[0]) && blk.outline?) end
Public: Get the String text of this ListItem with substitutions applied.
By default, normal substitutions are applied to the text. The substitutions can be modified by altering the subs property of this object.
Returns the converted String text for this ListItem
# File lib/asciidoctor/list.rb, line 74 def text apply_subs @text, @subs end
Public: A convenience method that checks whether the text of this list item is not blank (i.e., not nil or empty string).
# File lib/asciidoctor/list.rb, line 64 def text? !@text.nil_or_empty? end
# File lib/asciidoctor/list.rb, line 125 def to_s %(#<#{self.class}@#{object_id} {list_context: #{parent.context.inspect}, text: #{@text.inspect}, blocks: #{(@blocks || []).size}}>) end