class RDoc::Markup::ToBs

Outputs RDoc markup with hot backspace action! You will probably need a pager to use this output format.

This formatter won’t work on 1.8.6 because it lacks String#chars.

Public Class Methods

Returns a new ToBs that is ready for hot backspace action!

Calls superclass method RDoc::Markup::ToRdoc::new
# File lib/rdoc/markup/to_bs.rb, line 13
def initialize(markup = nil)
  super

  @in_b  = false
  @in_em = false
end

Public Instance Methods

Makes heading text bold.

# File lib/rdoc/markup/to_bs.rb, line 48
def accept_heading(heading)
  use_prefix or @res << ' ' * @indent
  @res << @headings[heading.level][0]
  @in_b = true
  @res << attributes(heading.text)
  @in_b = false
  @res << @headings[heading.level][1]
  @res << "\n"
end

Prepares the visitor for consuming list_item

# File lib/rdoc/markup/to_bs.rb, line 61
def accept_list_item_start(list_item)
  type = @list_type.last

  case type
  when :NOTE, :LABEL then
    bullets = Array(list_item.label).map do |label|
      attributes(label).strip
    end.join "\n"

    bullets << ":\n" unless bullets.empty?

    @prefix = ' ' * @indent
    @indent += 2
    @prefix << bullets + (' ' * @indent)
  else
    bullet = type == :BULLET ? '*' :  @list_index.last.to_s + '.'
    @prefix = (' ' * @indent) + bullet.ljust(bullet.length + 1)
    width = bullet.length + 1
    @indent += width
  end
end
# File lib/rdoc/markup/to_bs.rb, line 27
def add_text(text)
  attrs = @attributes.keys
  if attrs.include? :BOLD
    styled = +''
    text.chars.each do |c|
      styled << "#{c}\b#{c}"
    end
    text = styled
  elsif attrs.include? :EM
    styled = +''
    text.chars.each do |c|
      styled << "_\b#{c}"
    end
    text = styled
  end
  emit_inline(text)
end
# File lib/rdoc/markup/to_bs.rb, line 83
def calculate_text_width(text)
  text.gsub(/_\x08/, '').gsub(/\x08./, '').size
end
Calls superclass method RDoc::Markup::ToRdoc#handle_inline
# File lib/rdoc/markup/to_bs.rb, line 20
def handle_inline(text)
  initial_style = []
  initial_style << :BOLD if @in_b
  initial_style << :EM   if @in_em
  super(text, initial_style)
end