diff options
Diffstat (limited to 'lib/rdoc/markup/to_rdoc.rb')
-rw-r--r-- | lib/rdoc/markup/to_rdoc.rb | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/lib/rdoc/markup/to_rdoc.rb b/lib/rdoc/markup/to_rdoc.rb index 6f2faac2f6..f16b4ed5a3 100644 --- a/lib/rdoc/markup/to_rdoc.rb +++ b/lib/rdoc/markup/to_rdoc.rb @@ -1,6 +1,3 @@ -require 'rdoc/markup/formatter' -require 'rdoc/markup/inline' - ## # Outputs RDoc markup as RDoc markup! (mostly) @@ -45,7 +42,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter # Creates a new formatter that will output (mostly) \RDoc markup def initialize markup = nil - super + super nil, markup @markup.add_special(/\\\S/, :SUPPRESSED_CROSSREF) @width = 78 @@ -60,6 +57,8 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter @headings[4] = ['==== ', ''] @headings[5] = ['===== ', ''] @headings[6] = ['====== ', ''] + + @hard_break = "\n" end ## @@ -79,6 +78,21 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter end ## + # Adds +paragraph+ to the output + + def accept_block_quote block_quote + @indent += 2 + + block_quote.parts.each do |part| + @prefix = '> ' + + part.accept self + end + + @indent -= 2 + end + + ## # Adds +heading+ to the output def accept_heading heading @@ -106,6 +120,11 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter when :BULLET then 2 when :NOTE, :LABEL then + if @prefix then + @res << @prefix.strip + @prefix = nil + end + @res << "\n" 2 else @@ -125,10 +144,15 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter case type when :NOTE, :LABEL then - bullet = attributes(list_item.label) + ":\n" + bullets = Array(list_item.label).map do |label| + attributes(label).strip + end.join "\n" + + bullets << ":\n" unless bullets.empty? + @prefix = ' ' * @indent @indent += 2 - @prefix << bullet + (' ' * @indent) + @prefix << bullets + (' ' * @indent) else bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.' @prefix = (' ' * @indent) + bullet.ljust(bullet.length + 1) @@ -168,7 +192,8 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter # Adds +paragraph+ to the output def accept_paragraph paragraph - wrap attributes(paragraph.text) + text = paragraph.text @hard_break + wrap attributes text end ## @@ -176,7 +201,8 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter def accept_indented_paragraph paragraph @indent += paragraph.indent - wrap attributes(paragraph.text) + text = paragraph.text @hard_break + wrap attributes text @indent -= paragraph.indent end @@ -235,6 +261,13 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter end ## + # Adds a newline to the output + + def handle_special_HARD_BREAK special + "\n" + end + + ## # Prepares the visitor for text generation def start_accepting @@ -252,8 +285,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter # prefix for later consumption. def use_prefix - prefix = @prefix - @prefix = nil + prefix, @prefix = @prefix, nil @res << prefix if prefix prefix |