Class: RDoc::Markup::ToBs (Ruby 2.3.7)
Description: Class : RDoc::Markup::ToBs - Ruby 2.3.7

- Home
- Core 2.3.7
- Std-lib 2.3.7
- Downloads

Support for the Ruby 2.3 series has ended. See here for reference.

### Home Classes Methods

### In Files

- rdoc/markup/to_bs.rb

### Parent

RDoc::Markup::ToRdoc

### Methods

- ::new
- #accept_heading
- #annotate
- #convert_special
- #convert_string
- #init_tags

### Class/Module Index

Quicksearch

- RDoc
- RDoc::Alias
- RDoc::AnonClass
- RDoc::AnyMethod
- RDoc::Attr
- RDoc::ClassModule
- RDoc::CodeObject
- RDoc::Comment
- RDoc::Constant
- RDoc::Context
- RDoc::Context::Section
- RDoc::CrossReference
- RDoc::ERBIO
- RDoc::ERBPartial
- RDoc::Encoding
- RDoc::Error
- RDoc::Extend
- RDoc::Generator
- RDoc::Generator::Darkfish
- RDoc::Generator::JsonIndex
- RDoc::Generator::Markup
- RDoc::Generator::POT
- RDoc::Generator::POT::MessageExtractor
- RDoc::Generator::POT::PO
- RDoc::Generator::POT::POEntry
- RDoc::Generator::RI
- RDoc::GhostMethod
- RDoc::I18n
- RDoc::I18n::Locale
- RDoc::I18n::Text
- RDoc::Include
- RDoc::Markdown
- RDoc::Markdown::Literals
- RDoc::Markup
- RDoc::Markup::AttrChanger
- RDoc::Markup::AttrSpan
- RDoc::Markup::AttributeManager
- RDoc::Markup::Attributes
- RDoc::Markup::BlankLine
- RDoc::Markup::BlockQuote
- RDoc::Markup::Document
- RDoc::Markup::Formatter
- RDoc::Markup::FormatterTestCase
- RDoc::Markup::HardBreak
- RDoc::Markup::Include
- RDoc::Markup::IndentedParagraph
- RDoc::Markup::List
- RDoc::Markup::ListItem
- RDoc::Markup::Paragraph
- RDoc::Markup::Parser
- RDoc::Markup::Parser::Error
- RDoc::Markup::Parser::ParseError
- RDoc::Markup::PreProcess
- RDoc::Markup::Raw
- RDoc::Markup::Rule
- RDoc::Markup::Special
- RDoc::Markup::TextFormatterTestCase
- RDoc::Markup::ToAnsi
- RDoc::Markup::ToBs
- RDoc::Markup::ToHtml
- RDoc::Markup::ToHtmlCrossref
- RDoc::Markup::ToHtmlSnippet
- RDoc::Markup::ToJoinedParagraph
- RDoc::Markup::ToLabel
- RDoc::Markup::ToMarkdown
- RDoc::Markup::ToRdoc
- RDoc::Markup::ToTableOfContents
- RDoc::Markup::ToTest
- RDoc::Markup::ToTtOnly
- RDoc::Markup::Verbatim
- RDoc::MetaMethod
- RDoc::MethodAttr
- RDoc::Mixin
- RDoc::NormalClass
- RDoc::NormalModule
- RDoc::Options
- RDoc::Parser
- RDoc::Parser::C
- RDoc::Parser::ChangeLog
- RDoc::Parser::Markdown
- RDoc::Parser::RD
- RDoc::Parser::Ruby
- RDoc::Parser::RubyTools
- RDoc::Parser::Simple
- RDoc::Parser::Text
- RDoc::RD
- RDoc::RD::BlockParser
- RDoc::RD::Inline
- RDoc::RD::InlineParser
- RDoc::RDoc
- RDoc::RI
- RDoc::RI::Driver
- RDoc::RI::Driver::Error
- RDoc::RI::Driver::NotFoundError
- RDoc::RI::Error
- RDoc::RI::Paths
- RDoc::RI::Task
- RDoc::Require
- RDoc::RubyLex
- RDoc::RubyLex::Error
- RDoc::RubyToken
- RDoc::RubygemsHook
- RDoc::Servlet
- RDoc::SingleClass
- RDoc::Stats
- RDoc::Stats::Normal
- RDoc::Stats::Quiet
- RDoc::Stats::Verbose
- RDoc::Store
- RDoc::Store::Error
- RDoc::Store::MissingFileError
- RDoc::Task
- RDoc::TestCase
- RDoc::Text
- RDoc::TokenStream
- RDoc::TomDoc
- RDoc::TopLevel
- RDocTask
- Test

No matching classes.

# 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

new(markup = nil) click to toggle source

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

                   # File rdoc/markup/to_bs.rb, line 12
    def initialize markup = nil
      super

      @in_b  = false
      @in_em = false
    end

### Public Instance Methods

accept_heading(heading) click to toggle source

Makes heading text bold.

                   # File rdoc/markup/to_bs.rb, line 32
    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

annotate(tag) click to toggle source

Turns on or off special handling for `convert_string`

                   # File rdoc/markup/to_bs.rb, line 45
    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_special(special) click to toggle source

Calls #convert_string on the result of #convert_special

                   # File rdoc/markup/to_bs.rb, line 58
    def convert_special special
      convert_string super
    end

convert_string(string) click to toggle source

Adds bold or underline mixed with backspaces

                   # File rdoc/markup/to_bs.rb, line 65
    def convert_string string
      return string unless string.respond_to? :chars # your ruby is lame
      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() click to toggle source

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

                   # File rdoc/markup/to_bs.rb, line 23
    def init_tags
      add_tag :BOLD, '+b', '-b'
      add_tag :EM,   '+_', '-_'
      add_tag :TT,   ''  , ''   # we need in_tt information maintained
    end