1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/rdoc/markup/to_joined_paragraph.rb
drbrain 85e3560a3b * lib/rdoc/markup/to_joined_paragraph.rb: Completed documentation
* lib/rdoc/parser/c.rb:  ditto
* lib/rdoc/parser/changelog.rb:  ditto
* lib/rdoc/servlet.rb:  ditto
* lib/rdoc/store.rb:  ditto

* lib/rdoc/store.rb:  Improved HTML error page.  Completed
  documentation

* lib/rdoc/parser/ruby.rb:  Fixed bug attaching a comment to A::B = 42
* test/rdoc/test_rdoc_parser_ruby.rb:  Test for above

* test/rdoc/test_rdoc_comment.rb:  Removed garbage


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-07 05:22:50 +00:00

71 lines
1.5 KiB
Ruby

##
# Joins the parts of an RDoc::Markup::Paragraph into a single String.
#
# This allows for easier maintenance and testing of Markdown support.
#
# This formatter only works on Paragraph instances. Attempting to process
# other markup syntax items will not work.
class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
def initialize # :nodoc:
super nil
end
def start_accepting # :nodoc:
end
def end_accepting # :nodoc:
end
##
# Converts the parts of +paragraph+ to a single entry.
def accept_paragraph paragraph
parts = []
string = false
paragraph.parts.each do |part|
if String === part then
if string then
string << part
else
parts << part
string = part
end
else
parts << part
string = false
end
end
parts = parts.map do |part|
if String === part then
part.rstrip
else
part
end
end
# TODO use Enumerable#chunk when ruby 1.8 support is dropped
#parts = paragraph.parts.chunk do |part|
# String === part
#end.map do |string, chunk|
# string ? chunk.join.rstrip : chunk
#end.flatten
paragraph.parts.replace parts
end
alias accept_block_quote ignore
alias accept_heading ignore
alias accept_list_end ignore
alias accept_list_item_end ignore
alias accept_list_item_start ignore
alias accept_list_start ignore
alias accept_raw ignore
alias accept_rule ignore
alias accept_verbatim ignore
end