class Asciidoctor::Table::Cell

Public: Methods for managing the a cell in an AsciiDoc table.

def content

Returns the converted String for this Cell

This method should not be used for cells in the head row or that have the literal or verse style.

Public: Handles the body data (tbody, tfoot), applying styles and partitioning into paragraphs
def content
  if (cell_style = @style) == :asciidoc
    @inner_document.convert
  elsif @text.include? DOUBLE_LF
    (text.split BlankLineRx).map do |para|
      cell_style && cell_style != :header ? (Inline.new parent, :quoted, para, type: cell_style).convert : para
    end
  elsif (subbed_text = text).empty?
    []
  elsif cell_style && cell_style != :header
    [(Inline.new parent, :quoted, subbed_text, type: cell_style).convert]
  else
    [subbed_text]
  end
end

def file

Public: Get the source file where this block started
def file
  @source_location && @source_location.file
end

def initialize column, cell_text, attributes = {}, opts = {}

def initialize column, cell_text, attributes = {}, opts = {}
  super column, :table_cell
  @source_location = opts[:cursor].dup if @document.sourcemap
  if column
    cell_style = column.attributes['style'] unless (in_header_row = column.table.header_row?)
    # REVIEW feels hacky to inherit all attributes from column
    update_attributes column.attributes
  end
  # NOTE if attributes is defined, we know this is a psv cell; implies text needs to be stripped
  if attributes
    if attributes.empty?
      @colspan = @rowspan = nil
    else
      @colspan, @rowspan = (attributes.delete 'colspan'), (attributes.delete 'rowspan')
      # TODO delete style attribute from @attributes if set
      cell_style = attributes['style'] || cell_style unless in_header_row
      update_attributes attributes
    end
    if cell_style == :asciidoc
      asciidoc = true
      inner_document_cursor = opts[:cursor]
      if (cell_text = cell_text.rstrip).start_with? LF
        lines_advanced = 1
        lines_advanced += 1 while (cell_text = cell_text.slice 1, cell_text.length).start_with? LF
        # NOTE this only works if we remain in the same file
        inner_document_cursor.advance lines_advanced
      else
        cell_text = cell_text.lstrip
      end
    elsif cell_style == :literal
      literal = true
      cell_text = cell_text.rstrip
      # QUESTION should we use same logic as :asciidoc cell? strip leading space if text doesn't start with newline?
      cell_text = cell_text.slice 1, cell_text.length while cell_text.start_with? LF
    else
      normal_psv = true
      # NOTE AsciidoctorJ uses nil cell_text to create an empty cell
      cell_text = cell_text ? cell_text.strip : ''
    end
  else
    @colspan = @rowspan = nil
    if cell_style == :asciidoc
      asciidoc = true
      inner_document_cursor = opts[:cursor]
    end
  end
  # NOTE only true for non-header rows
  if asciidoc
    # FIXME hide doctitle from nested document; temporary workaround to fix
    # nested document seeing doctitle and assuming it has its own document title
    parent_doctitle = @document.attributes.delete('doctitle')
    # NOTE we need to process the first line of content as it may not have been processed
    # the included content cannot expect to match conditional terminators in the remaining
    # lines of table cell content, it must be self-contained logic
    # QUESTION should we reset cell_text to nil?
    # QUESTION is is faster to check for :: before splitting?
    inner_document_lines = cell_text.split LF, -1
    if (unprocessed_line1 = inner_document_lines[0]).include? '::'
      preprocessed_lines = (PreprocessorReader.new @document, [unprocessed_line1]).readlines
      unless unprocessed_line1 == preprocessed_lines[0] && preprocessed_lines.size < 2
        inner_document_lines.shift
        inner_document_lines.unshift(*preprocessed_lines) unless preprocessed_lines.empty?
      end
    end unless inner_document_lines.empty?
    @inner_document = Document.new inner_document_lines, standalone: false, parent: @document, cursor: inner_document_cursor
    @document.attributes['doctitle'] = parent_doctitle unless parent_doctitle.nil?
    @subs = nil
  elsif literal
    @content_model = :verbatim
    @subs = BASIC_SUBS
  else
    if normal_psv && (cell_text.start_with? '[[') && LeadingInlineAnchorRx =~ cell_text
      Parser.catalog_inline_anchor $1, $2, self, opts[:cursor], @document
    end
    @content_model = :simple
    @subs = NORMAL_SUBS
  end
  @text = cell_text
  @style = cell_style
end

def lineno

Public: Get the source line number where this block started
def lineno
  @source_location && @source_location.lineno
end

def text

Returns the converted String text for this Cell

This method shouldn't be used for cells that have the AsciiDoc style.

the foot row and body.
Used for cells in the head row as well as text-only (non-AsciiDoc) cells in

Public: Get the String text of this cell with substitutions applied.
def text
  apply_subs @text, @subs
end

def text= val

Returns the new String text assigned to this Cell

This method shouldn't be used for cells that have the AsciiDoc style.

Public: Set the String text.
def text= val
  @text = val
end

def to_s

def to_s
  "#{super.to_s} - [text: #@text, colspan: #{@colspan || 1}, rowspan: #{@rowspan || 1}, attributes: #@attributes]"
end