method
wrap
v2_2_9 -
Show latest stable
- Class:
RDoc::Markup::ToRdoc
wrap(text)public
Wraps text to #width
# File lib/rdoc/markup/to_rdoc.rb, line 297
def wrap text
return unless text && !text.empty?
text_len = @width - @indent
text_len = 20 if text_len < 20
re = /^(.{0,#{text_len}})[ \n]/
next_prefix = ' ' * @indent
prefix = @prefix || next_prefix
@prefix = nil
@res << prefix
while text.length > text_len
if text =~ re then
@res << $1
text.slice!(0, $&.length)
else
@res << text.slice!(0, text_len)
end
@res << "\n" << next_prefix
end
if text.empty? then
@res.pop
@res.pop
else
@res << text
@res << "\n"
end
end Related methods
- Instance methods
- accept_blank_line
- accept_block_quote
- accept_heading
- accept_indented_paragraph
- accept_list_end
- accept_list_item_end
- accept_list_item_start
- accept_list_start
- accept_paragraph
- accept_raw
- accept_rule
- accept_verbatim
- attributes
- end_accepting
- handle_special_HARD_BREAK
- handle_special_SUPPRESSED_CROSSREF
- init_tags
- start_accepting
- use_prefix
- wrap
- Class methods
- new