123456789_123456789_123456789_123456789_123456789_

Class: RDoc::Markup::ToBs

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ToRdoc, Formatter
Instance Chain:
self, ToRdoc, Formatter
Inherits: RDoc::Markup::ToRdoc
Defined in: lib/rdoc/markup/to_bs.rb

Overview

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.

Class Method Summary

ToRdoc - Inherited

.new

Creates a new formatter that will output (mostly) RDoc markup.

Formatter - Inherited

.gen_relative_url

Converts a target url to one that is relative to a given path.

.new

Creates a new Formatter.

Instance Attribute Summary

ToRdoc - Inherited

#indent

Current indent amount for output in characters.

#list_index

Stack of current list indexes for alphabetic and numeric lists.

#list_type

Stack of list types.

#list_width

Stack of list widths for indentation.

#prefix

Prefix for the next list item.

#res

Output accumulator.

#width

Output width in characters.

Formatter - Inherited

#in_tt?

Are we currently inside tt tags?

Instance Method Summary

ToRdoc - Inherited

#accept_blank_line

Adds blank_line to the output.

#accept_block_quote

Adds paragraph to the output.

#accept_heading

Adds heading to the output.

#accept_indented_paragraph

Adds paragraph to the output.

#accept_list_end

Finishes consumption of list

#accept_list_item_end

Finishes consumption of list_item

#accept_list_item_start

Prepares the visitor for consuming list_item

#accept_list_start

Prepares the visitor for consuming list

#accept_paragraph

Adds paragraph to the output.

#accept_raw

Adds raw to the output.

#accept_rule

Adds rule to the output.

#accept_table

Adds table to the output.

#accept_verbatim

Outputs verbatim indented 2 columns.

#attributes

Applies attribute-specific markup to text using RDoc::AttributeManager

#end_accepting

Returns the generated output.

#handle_regexp_HARD_BREAK

Adds a newline to the output.

#handle_regexp_SUPPRESSED_CROSSREF

Removes preceding \ from the suppressed crossref target

#init_tags

Maps attributes to HTML sequences.

#start_accepting

Prepares the visitor for text generation.

#use_prefix

Adds the stored #prefix to the output and clears it.

#wrap

Wraps text to #width

Formatter - Inherited

#accept_document

Adds document to the output.

#add_regexp_handling_RDOCLINK

Adds a regexp handling for links of the form rdoc-…:

#add_regexp_handling_TIDYLINK

Adds a regexp handling for links of the form <text> and <word>.

#add_tag

Add a new set of tags for an attribute.

#annotate

Allows tag to be decorated with additional information.

#convert

Marks up content

#convert_flow

Converts flow items flow

#convert_regexp_handling

Converts added regexp handlings.

#convert_string

Converts a string to be fancier if desired.

#ignore

Use ignore in your subclass to ignore the content of a node.

#off_tags

Turns off tags for item on res

#on_tags

Turns on tags for item on res

#parse_url

Extracts and a scheme, url and an anchor id from url and returns them.

#tt?

Is tag a tt tag?

Constructor Details

.new(markup = nil) ⇒ ToBs

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

[ GitHub ]

  
# File 'lib/rdoc/markup/to_bs.rb', line 13

def initialize markup = nil
  super

  @in_b  = false
  @in_em = false
end

Instance Method Details

#accept_heading(heading)

Makes heading text bold.

[ GitHub ]

  
# File 'lib/rdoc/markup/to_bs.rb', line 33

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

#accept_list_item_start(list_item)

Prepares the visitor for consuming list_item

[ GitHub ]

  
# File 'lib/rdoc/markup/to_bs.rb', line 46

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

#annotate(tag)

Turns on or off regexp handling for #convert_string

[ GitHub ]

  
# File 'lib/rdoc/markup/to_bs.rb', line 71

def annotate tag
  case tag
  when '+b' then @in_b = true
  when '-b' then @in_b = false
  when '+_' then @in_em = true
  when '-_' then @in_em = false
  end
  ''
end

#convert_regexp_handling(target)

Calls convert_string on the result of convert_regexp_handling

[ GitHub ]

  
# File 'lib/rdoc/markup/to_bs.rb', line 84

def convert_regexp_handling target
  convert_string super
end

#convert_string(string)

Adds bold or underline mixed with backspaces

[ GitHub ]

  
# File 'lib/rdoc/markup/to_bs.rb', line 91

def convert_string string
  return string unless @in_b or @in_em
  chars = if @in_b then
            string.chars.map do |char| "#{char}\b#{char}" end
          elsif @in_em then
            string.chars.map do |char| "_\b#{char}" end
          end

  chars.join
end

#init_tags

Sets a flag that is picked up by #annotate to do the right thing in #convert_string

[ GitHub ]

  
# File 'lib/rdoc/markup/to_bs.rb', line 24

def init_tags
  add_tag :BOLD, '+b', '-b'
  add_tag :EM,   '+_', '-_'
  add_tag :TT,   ''  , ''   # we need in_tt information maintained
end