Class: RDoc::Generator::Mdoc::Formatter
- Inherits:
-
Markup::Formatter
- Object
- Markup::Formatter
- RDoc::Generator::Mdoc::Formatter
- Includes:
- Helpers
- Defined in:
- lib/rdoc/generator/mdoc/formatter.rb
Overview
Format an RDoc::Document into mdoc.
Instance Method Summary collapse
-
#accept_blank_line(blank_line) ⇒ Object
Output paragraph macros for blank lines.
-
#accept_block_quote(block_quote) ⇒ Object
Turn a large quoted section into a block display.
-
#accept_heading(heading) ⇒ Object
Turn a heading into a subsection header.
-
#accept_list_end(list) ⇒ Object
Close a list.
-
#accept_list_item_end(list_item) ⇒ Object
Finish a list item.
-
#accept_list_item_start(list_item) ⇒ Object
Open a list item.
-
#accept_list_start(list) ⇒ Object
Open an enumerated, dictionary, or bulleted list.
-
#accept_paragraph(paragraph) ⇒ Object
Output a paragraph macro for the escaped paragraph.
-
#accept_raw(raw) ⇒ Object
Pass through all raw parts unparsed, separated by newlines.
-
#accept_rule(rule) ⇒ Object
Format a horizontal ruler.
-
#accept_verbatim(verbatim) ⇒ Object
Format code as an indented block.
-
#end_accepting ⇒ Object
Compile the parts together.
-
#initialize(options = nil, markup = nil) ⇒ Formatter
constructor
Instantiate a mdoc formatter that escapes special mdoc characters.
-
#start_accepting ⇒ Object
Initialize the formatter with an empty array of parts and lists.
Methods included from Helpers
Constructor Details
#initialize(options = nil, markup = nil) ⇒ Formatter
Instantiate a mdoc formatter that escapes special mdoc characters.
12 13 14 15 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 12 def initialize(=nil, markup = nil) super end |
Instance Method Details
#accept_blank_line(blank_line) ⇒ Object
Output paragraph macros for blank lines.
53 54 55 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 53 def accept_blank_line(blank_line) parts << "\n.Pp\n" end |
#accept_block_quote(block_quote) ⇒ Object
Turn a large quoted section into a block display.
45 46 47 48 49 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 45 def accept_block_quote(block_quote) parts << ".Bd -offset indent\n" block_quote.parts.each { |part| part.accept self } parts << "\n.Ed\n.Pp\n" end |
#accept_heading(heading) ⇒ Object
Turn a heading into a subsection header.
32 33 34 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 32 def accept_heading(heading) parts << ".Ss #{heading.text}\n" end |
#accept_list_end(list) ⇒ Object
Close a list.
This works for all list types.
78 79 80 81 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 78 def accept_list_end(list) list_types.pop parts << ".El\n" end |
#accept_list_item_end(list_item) ⇒ Object
Finish a list item.
This works for all list types.
104 105 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 104 def accept_list_item_end(list_item) end |
#accept_list_item_start(list_item) ⇒ Object
Open a list item.
If the list has a label, that label is the list item. Otherwise, the list item has no content.
Also see #accept_list_item_end.
90 91 92 93 94 95 96 97 98 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 90 def accept_list_item_start(list_item) case current_list_type when :LABEL, :NOTE labels = Array(list_item.label).join(", ") parts << ".It #{labels}\n" else parts << ".It\n" end end |
#accept_list_start(list) ⇒ Object
Open an enumerated, dictionary, or bulleted list.
The list must be closed using #accept_list_start.
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 61 def accept_list_start(list) list_types.push(list.type) case current_list_type when :NUMBER, :LALPHA, :UALPHA parts << ".Bl -enum\n" when :LABEL, :NOTE parts << ".Bl -hang -offset -indent\n" else parts << ".Bl -bullet\n" end end |
#accept_paragraph(paragraph) ⇒ Object
Output a paragraph macro for the escaped paragraph.
38 39 40 41 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 38 def accept_paragraph(paragraph) parts << handle_inline_attributes(paragraph.text) parts << "\n.Pp\n" end |
#accept_raw(raw) ⇒ Object
Pass through all raw parts unparsed, separated by newlines.
124 125 126 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 124 def accept_raw(raw) parts << raw.parts.join("\n") end |
#accept_rule(rule) ⇒ Object
Format a horizontal ruler.
This is a no-op.
119 120 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 119 def accept_rule(rule) end |
#accept_verbatim(verbatim) ⇒ Object
Format code as an indented block.
109 110 111 112 113 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 109 def accept_verbatim(verbatim) parts << ".Bd -literal -offset indent\n" parts << verbatim.text parts << "\n.Ed\n.Pp\n" end |
#end_accepting ⇒ Object
Compile the parts together.
26 27 28 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 26 def end_accepting handle_leading_punctuation parts.join.squeeze("\n") end |
#start_accepting ⇒ Object
Initialize the formatter with an empty array of parts and lists.
19 20 21 22 |
# File 'lib/rdoc/generator/mdoc/formatter.rb', line 19 def start_accepting @parts = [] @list_types = [] end |