Class: Asciidoctor::ListItem

Inherits:
AbstractBlock show all
Defined in:
lib/asciidoctor/list.rb

Overview

Methods for managing items for AsciiDoc olists, ulist, and dlists.

In a description list (dlist), each item is a tuple that consists of a 2-item Array of ListItem terms and a ListItem description (i.e., [[term, term, …], desc]. If a description is not set, then the second entry in the tuple is nil.

Constant Summary

Constants included from Substitutors

Substitutors::CAN, Substitutors::CGI, Substitutors::DEL, Substitutors::ESC_R_SB, Substitutors::HighlightedPassSlotRx, Substitutors::PASS_END, Substitutors::PASS_START, Substitutors::PLUS, Substitutors::PassSlotRx, Substitutors::QuotedTextSniffRx, Substitutors::RS, Substitutors::R_SB, Substitutors::SUB_GROUPS, Substitutors::SUB_HINTS, Substitutors::SUB_OPTIONS, Substitutors::SpecialCharsRx, Substitutors::SpecialCharsTr

Instance Attribute Summary collapse

Attributes inherited from AbstractBlock

#blocks, #caption, #content_model, #level, #numeral, #source_location, #style, #subs

Attributes inherited from AbstractNode

#attributes, #context, #document, #id, #node_name, #parent

Instance Method Summary collapse

Methods inherited from AbstractBlock

#<<, #alt, #assign_caption, #block?, #blocks?, #captioned_title, #content, #context=, #convert, #file, #find_by, #inline?, #lineno, #list_marker_keyword, #next_adjacent_block, #number, #number=, #remove_sub, #sections, #sections?, #sub?, #title, #title=, #title?, #xreftext

Methods inherited from AbstractNode

#add_role, #attr, #attr?, #block?, #converter, #enabled_options, #generate_data_uri, #generate_data_uri_from_uri, #has_role?, #icon_uri, #image_uri, #inline?, #is_uri?, #media_uri, #normalize_asset_path, #normalize_system_path, #normalize_web_path, #option?, #read_asset, #read_contents, #reftext, #reftext?, #remove_attr, #remove_role, #role, #role=, #role?, #roles, #set_attr, #set_option, #update_attributes

Methods included from Substitutors

#apply_header_subs, #apply_normal_subs, #apply_reftext_subs, #apply_subs, #expand_subs, #extract_passthroughs, #highlight_source, #resolve_block_subs, #resolve_lines_to_highlight, #resolve_pass_subs, #resolve_subs, #restore_passthroughs, #sub_attributes, #sub_callouts, #sub_macros, #sub_post_replacements, #sub_quotes, #sub_replacements, #sub_source, #sub_specialchars

Methods included from Logging

#logger, #message_with_context

Constructor Details

#initialize(parent, text = nil) ⇒ ListItem

Initialize an Asciidoctor::ListItem object.

Parameters:

  • parent

    The parent list block for this list item

  • text (defaults to: nil)

    the String text (default nil)



59
60
61
62
63
64
# File 'lib/asciidoctor/list.rb', line 59

def initialize parent, text = nil
  super parent, :list_item
  @text = text
  @level = parent.level
  @subs = NORMAL_SUBS.drop 0
end

Instance Attribute Details

#markerObject

Get/Set the String used to mark this list item



53
54
55
# File 'lib/asciidoctor/list.rb', line 53

def marker
  @marker
end

#textObject

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



78
79
80
81
# File 'lib/asciidoctor/list.rb', line 78

def text
  # NOTE @text can be nil if dd node only has block content
  @text && (apply_subs @text, @subs)
end

Instance Method Details

#compound?Boolean

Check whether this list item has compound content (nested blocks aside from a single outline list). Primarily relevant for outline lists.

Returns:

  • (Boolean)

    Return true if the list item contains blocks other than a single outline list. Otherwise, return false.



98
99
100
# File 'lib/asciidoctor/list.rb', line 98

def compound?
  !simple?
end

#simple?Boolean

Check whether this list item has simple content (no nested blocks aside from a single outline list). Primarily relevant for outline lists.

Returns:

  • (Boolean)

    Return true if the list item contains no blocks or it contains a single outline list. Otherwise, return false.



90
91
92
# File 'lib/asciidoctor/list.rb', line 90

def simple?
  @blocks.empty? || (@blocks.size == 1 && List === (blk = @blocks[0]) && blk.outline?)
end

#text?Boolean

A convenience method that checks whether the text of this list item is not blank (i.e., not nil or empty string).

Returns:

  • (Boolean)


68
69
70
# File 'lib/asciidoctor/list.rb', line 68

def text?
  @text.nil_or_empty? ? false : true
end

#to_sObject



110
111
112
# File 'lib/asciidoctor/list.rb', line 110

def to_s
  %(#<#{self.class}@#{object_id} {list_context: #{parent.context.inspect}, text: #{@text.inspect}, blocks: #{(@blocks || []).size}}>)
end