Class: RDoc::Markup::ToBs
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
|
|
|
Instance Chain:
|
|
| 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.
Constant Summary
ToRdoc - Inherited
Class Method Summary
-
.new(markup = nil) ⇒ ToBs
constructor
Returns a new
ToBsthat is ready for hot backspace action!
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 |
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. |
Instance Method Summary
-
#accept_heading(heading)
Makes heading text bold.
-
#accept_list_item_start(list_item)
Prepares the visitor for consuming
list_item - #add_text(text)
- #calculate_text_width(text)
- #handle_inline(text)
ToRdoc - Inherited
| #accept_blank_line | Adds |
| #accept_block_quote | Adds |
| #accept_heading | Adds |
| #accept_indented_paragraph | Adds |
| #accept_list_end | Finishes consumption of |
| #accept_list_item_end | Finishes consumption of |
| #accept_list_item_start | Prepares the visitor for consuming |
| #accept_list_start | Prepares the visitor for consuming |
| #accept_paragraph | Adds |
| #accept_raw | Adds |
| #accept_rule | Adds |
| #accept_table | Adds |
| #accept_verbatim | Outputs |
| #add_text, | |
| #attributes | Applies attribute-specific markup to |
| #calculate_text_width, #emit_inline, | |
| #end_accepting | Returns the generated output. |
| #handle_BOLD, #handle_BOLD_WORD, #handle_EM, #handle_EM_WORD, #handle_HARD_BREAK, #handle_inline, #handle_PLAIN_TEXT, #handle_REGEXP_HANDLING_TEXT, | |
| #handle_regexp_SUPPRESSED_CROSSREF | Removes preceding \ from the suppressed crossref |
| #handle_STRIKE, #handle_TIDYLINK, #handle_TT, #off, #on, | |
| #start_accepting | Prepares the visitor for text generation. |
| #use_prefix | Adds the stored |
| #wrap | Wraps |
Formatter - Inherited
| #accept_document | Adds |
| #add_regexp_handling_RDOCLINK | Adds a regexp handling for links of the form rdoc-…: |
| #annotate | Allows |
| #apply_regexp_handling | Applies regexp handling to |
| #convert | Marks up |
| #convert_string | Converts a string to be fancier if desired. |
| #handle_BOLD | Called when processing bold nodes while traversing inline nodes from handle_inline. |
| #handle_BOLD_WORD | Called when processing bold word nodes while traversing inline nodes from handle_inline. |
| #handle_EM | Called when processing emphasis nodes while traversing inline nodes from handle_inline. |
| #handle_EM_WORD | Called when processing emphasis word nodes while traversing inline nodes from handle_inline. |
| #handle_HARD_BREAK | Called when processing a hard break while traversing inline nodes from handle_inline. |
| #handle_inline | Parses inline |
| #handle_PLAIN_TEXT | Called when processing plain text while traversing inline nodes from handle_inline. |
| #handle_REGEXP_HANDLING_TEXT | Called when processing regexp-handling-processed text while traversing inline nodes from handle_inline. |
| #handle_STRIKE | Called when processing strike nodes while traversing inline nodes from handle_inline. |
| #handle_TEXT | Called when processing text node while traversing inline nodes from handle_inline. |
| #handle_TIDYLINK | Called when processing tidylink nodes while traversing inline nodes from handle_inline. |
| #handle_TT | Called when processing tt nodes while traversing inline nodes from handle_inline. |
| #ignore | Use ignore in your subclass to ignore the content of a node. |
| #parse_url | Extracts and a scheme, url and an anchor id from |
| #traverse_inline_nodes | Traverses |
| #tt? | Is |
Constructor Details
.new(markup = nil) ⇒ ToBs
Returns a new ToBs that is ready for hot backspace action!
# 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.
# 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
#accept_list_item_start(list_item)
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
#add_text(text)
[ GitHub ]# 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
#calculate_text_width(text)
[ GitHub ]# File 'lib/rdoc/markup/to_bs.rb', line 83
def calculate_text_width(text) text.gsub(/_\x08/, '').gsub(/\x08./, '').size end
#handle_inline(text)
[ GitHub ]# 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