class HtmlToAnsi::Html::Conversions::TextNode

Attributes

format[R]
text[R]

Public Class Methods

new(text, format) click to toggle source
# File lib/html_to_ansi/html/conversions.rb, line 44
def initialize text, format
  @text = text
  @format = format
end

Public Instance Methods

render() click to toggle source
# File lib/html_to_ansi/html/conversions.rb, line 48
def render
  return @text if format.include?(Extra::PRE)
  index = parent.children.index(self)
  if index > 0
    prev = parent.children[index - 1]
    if prev.kind_of?(TextNode) and prev.format == format
      if prev.text.match(/ $/)
        return @text.lstrip
      else
        return @text
      end
    end
  end
  if @@prev_format == format
    @text
  else
    @prev_format = format
    HtmlToAnsi::Ansi.graphics_mode(*format) + @text
  end
end