Class: RDoc::Markup::ToTtOnly
- Inherits:
-
Markup::Formatter
- Object
- Markup::Formatter
- RDoc::Markup::ToTtOnly
- Defined in:
- lib/rdoc/markup/to_tt_only.rb
Overview
Extracts sections of text enclosed in plus, tt or code. Used to discover undocumented parameters.
Instance Attribute Summary collapse
-
#list_type ⇒ Object
readonly
Stack of list types.
-
#res ⇒ Object
readonly
Output accumulator.
Instance Method Summary collapse
-
#accept_block_quote(block_quote) ⇒ Object
Adds tts from
block_quoteto the output. -
#accept_list_end(list) ⇒ Object
Pops the list type for
listfrom #list_type. -
#accept_list_item_start(list_item) ⇒ Object
Prepares the visitor for consuming
list_item. -
#accept_list_start(list) ⇒ Object
Pushes the list type for
listonto #list_type. -
#accept_paragraph(paragraph) ⇒ Object
Adds
paragraphto the output. -
#do_nothing(markup_item) ⇒ Object
(also: #accept_blank_line, #accept_heading, #accept_list_item_end, #accept_raw, #accept_rule, #accept_verbatim)
Does nothing to
markup_itembecause it doesn't have any user-built content. -
#end_accepting ⇒ Object
Returns an Array of items that were wrapped in plus, tt or code.
-
#start_accepting ⇒ Object
Prepares the visitor for gathering tt sections.
-
#tt_sections(text) ⇒ Object
Extracts tt sections from
text.
Instance Attribute Details
#list_type ⇒ Object (readonly)
Stack of list types
13 14 15 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 13 def list_type @list_type end |
#res ⇒ Object (readonly)
Output accumulator
18 19 20 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 18 def res @res end |
Instance Method Details
#accept_block_quote(block_quote) ⇒ Object
Adds tts from block_quote to the output
23 24 25 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 23 def accept_block_quote(block_quote) tt_sections block_quote.text end |
#accept_list_end(list) ⇒ Object
Pops the list type for list from #list_type
30 31 32 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 30 def accept_list_end(list) @list_type.pop end |
#accept_list_item_start(list_item) ⇒ Object
Prepares the visitor for consuming list_item
44 45 46 47 48 49 50 51 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 44 def accept_list_item_start(list_item) case @list_type.last when :NOTE, :LABEL Array(list_item.label).map do |label| tt_sections label end.flatten end end |
#accept_list_start(list) ⇒ Object
Pushes the list type for list onto #list_type
37 38 39 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 37 def accept_list_start(list) @list_type << list.type end |
#accept_paragraph(paragraph) ⇒ Object
Adds paragraph to the output
56 57 58 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 56 def accept_paragraph(paragraph) tt_sections(paragraph.text) end |
#do_nothing(markup_item) ⇒ Object Also known as: accept_blank_line, accept_heading, accept_list_item_end, accept_raw, accept_rule, accept_verbatim
Does nothing to markup_item because it doesn't have any user-built
content
64 65 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 64 def do_nothing(markup_item) end |
#end_accepting ⇒ Object
Returns an Array of items that were wrapped in plus, tt or code.
96 97 98 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 96 def end_accepting @res.compact end |
#start_accepting ⇒ Object
Prepares the visitor for gathering tt sections
103 104 105 106 107 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 103 def start_accepting @res = [] @list_type = [] end |
#tt_sections(text) ⇒ Object
Extracts tt sections from text
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 77 def tt_sections(text) parsed = Markup::InlineParser.new(text).parse traverse = -> node { next if String === node if node[:type] == :TT res << nil res << node[:children][0] || '' res << nil else node[:children].each(&traverse) end } parsed.each(&traverse) res end |