diff options
Diffstat (limited to 'lib/rdoc/markup')
34 files changed, 150 insertions, 134 deletions
diff --git a/lib/rdoc/markup/attr_changer.rb b/lib/rdoc/markup/attr_changer.rb index 4c4bc6479e..e5ba470bb6 100644 --- a/lib/rdoc/markup/attr_changer.rb +++ b/lib/rdoc/markup/attr_changer.rb @@ -20,4 +20,3 @@ class RDoc::Markup::AttrChanger end end - diff --git a/lib/rdoc/markup/attr_span.rb b/lib/rdoc/markup/attr_span.rb index 20ef11cd6d..f1fabf1c3b 100644 --- a/lib/rdoc/markup/attr_span.rb +++ b/lib/rdoc/markup/attr_span.rb @@ -33,4 +33,3 @@ class RDoc::Markup::AttrSpan end end - diff --git a/lib/rdoc/markup/attribute_manager.rb b/lib/rdoc/markup/attribute_manager.rb index 50764510f3..f6eb06da95 100644 --- a/lib/rdoc/markup/attribute_manager.rb +++ b/lib/rdoc/markup/attribute_manager.rb @@ -1,8 +1,19 @@ # frozen_string_literal: true + ## # Manages changes of attributes in a block of text class RDoc::Markup::AttributeManager + unless ::MatchData.method_defined?(:match_length) + using ::Module.new { + refine(::MatchData) { + def match_length(nth) # :nodoc: + b, e = offset(nth) + e - b if b + end + } + } + end ## # The NUL character @@ -127,6 +138,7 @@ class RDoc::Markup::AttributeManager res end + # :nodoc: def exclusive?(attr) (attr & @exclusive_bitmap) != 0 end @@ -144,47 +156,42 @@ class RDoc::Markup::AttributeManager convert_attrs_word_pair_map(str, attrs, exclusive) end + # :nodoc: def convert_attrs_matching_word_pairs(str, attrs, exclusive) # first do matching ones tags = @matching_word_pairs.select { |start, bitmap| - if exclusive && exclusive?(bitmap) - true - elsif !exclusive && !exclusive?(bitmap) - true - else - false - end + exclusive == exclusive?(bitmap) }.keys return if tags.empty? - all_tags = @matching_word_pairs.keys + tags = "[#{tags.join("")}](?!#{PROTECT_ATTR})" + all_tags = "[#{@matching_word_pairs.keys.join("")}](?!#{PROTECT_ATTR})" - re = /(^|\W|[#{all_tags.join("")}])([#{tags.join("")}])(\2*[#\\]?[\w:.\/\[\]-]+?\S?)\2(?!\2)([#{all_tags.join("")}]|\W|$)/ + re = /(?:^|\W|#{all_tags})\K(#{tags})(\1*[#\\]?[\w:#{PROTECT_ATTR}.\/\[\]-]+?\S?)\1(?!\1)(?=#{all_tags}|\W|$)/ 1 while str.gsub!(re) { |orig| - attr = @matching_word_pairs[$2] - attr_updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr) - if attr_updated - $1 + NULL * $2.length + $3 + NULL * $2.length + $4 + a, w = (m = $~).values_at(1, 2) + attr = @matching_word_pairs[a] + if attrs.set_attrs(m.begin(2), w.length, attr) + a = NULL * a.length else - $1 + NON_PRINTING_START + $2 + NON_PRINTING_END + $3 + NON_PRINTING_START + $2 + NON_PRINTING_END + $4 + a = NON_PRINTING_START + a + NON_PRINTING_END end + a + w + a } str.delete!(NON_PRINTING_START + NON_PRINTING_END) end + # :nodoc: def convert_attrs_word_pair_map(str, attrs, exclusive) # then non-matching unless @word_pair_map.empty? then @word_pair_map.each do |regexp, attr| - if !exclusive - next if exclusive?(attr) - else - next if !exclusive?(attr) - end + next unless exclusive == exclusive?(attr) 1 while str.gsub!(regexp) { |orig| - updated = attrs.set_attrs($`.length + $1.length, $2.length, attr) + w = (m = ($~))[2] + updated = attrs.set_attrs(m.begin(2), w.length, attr) if updated - NULL * $1.length + $2 + NULL * $3.length + NULL * m.match_length(1) + w + NULL * m.match_length(3) else orig end @@ -198,20 +205,14 @@ class RDoc::Markup::AttributeManager def convert_html(str, attrs, exclusive = false) tags = @html_tags.select { |start, bitmap| - if exclusive && exclusive?(bitmap) - true - elsif !exclusive && !exclusive?(bitmap) - true - else - false - end + exclusive == exclusive?(bitmap) }.keys.join '|' 1 while str.gsub!(/<(#{tags})>(.*?)<\/\1>/i) { |orig| attr = @html_tags[$1.downcase] - html_length = $1.length + 2 + html_length = $~.match_length(1) + 2 # "<>".length seq = NULL * html_length - attrs.set_attrs($`.length + html_length, $2.length, attr) + attrs.set_attrs($~.begin(2), $~.match_length(2), attr) seq + $2 + seq + NULL } end @@ -221,11 +222,7 @@ class RDoc::Markup::AttributeManager def convert_regexp_handlings str, attrs, exclusive = false @regexp_handlings.each do |regexp, attribute| - if exclusive - next if !exclusive?(attribute) - else - next if exclusive?(attribute) - end + next unless exclusive == exclusive?(attribute) str.scan(regexp) do capture = $~.size == 1 ? 0 : 1 @@ -406,4 +403,3 @@ class RDoc::Markup::AttributeManager end end - diff --git a/lib/rdoc/markup/attributes.rb b/lib/rdoc/markup/attributes.rb index ce014ce928..d9d18b3059 100644 --- a/lib/rdoc/markup/attributes.rb +++ b/lib/rdoc/markup/attributes.rb @@ -68,4 +68,3 @@ class RDoc::Markup::Attributes end end - diff --git a/lib/rdoc/markup/blank_line.rb b/lib/rdoc/markup/blank_line.rb index 3129ab5e7f..f63ae9479c 100644 --- a/lib/rdoc/markup/blank_line.rb +++ b/lib/rdoc/markup/blank_line.rb @@ -25,4 +25,3 @@ class RDoc::Markup::BlankLine end end - diff --git a/lib/rdoc/markup/block_quote.rb b/lib/rdoc/markup/block_quote.rb index 7a4b3e36b0..d9fcbf213c 100644 --- a/lib/rdoc/markup/block_quote.rb +++ b/lib/rdoc/markup/block_quote.rb @@ -12,4 +12,3 @@ class RDoc::Markup::BlockQuote < RDoc::Markup::Raw end end - diff --git a/lib/rdoc/markup/document.rb b/lib/rdoc/markup/document.rb index f3a5de1fc3..94cf6a3666 100644 --- a/lib/rdoc/markup/document.rb +++ b/lib/rdoc/markup/document.rb @@ -162,4 +162,3 @@ class RDoc::Markup::Document end end - diff --git a/lib/rdoc/markup/formatter.rb b/lib/rdoc/markup/formatter.rb index 2bac76e838..9daffaabb8 100644 --- a/lib/rdoc/markup/formatter.rb +++ b/lib/rdoc/markup/formatter.rb @@ -90,7 +90,7 @@ class RDoc::Markup::Formatter def add_regexp_handling_TIDYLINK @markup.add_regexp_handling(/(?: - \{.*?\} | # multi-word label + \{[^{}]*\} | # multi-word label \b[^\s{}]+? # single-word label ) @@ -263,4 +263,3 @@ class RDoc::Markup::Formatter end end - diff --git a/lib/rdoc/markup/hard_break.rb b/lib/rdoc/markup/hard_break.rb index 046068d5c2..de1819c903 100644 --- a/lib/rdoc/markup/hard_break.rb +++ b/lib/rdoc/markup/hard_break.rb @@ -29,4 +29,3 @@ class RDoc::Markup::HardBreak end end - diff --git a/lib/rdoc/markup/heading.rb b/lib/rdoc/markup/heading.rb index 93a3a52000..02476e5226 100644 --- a/lib/rdoc/markup/heading.rb +++ b/lib/rdoc/markup/heading.rb @@ -76,4 +76,3 @@ RDoc::Markup::Heading = end end - diff --git a/lib/rdoc/markup/include.rb b/lib/rdoc/markup/include.rb index ad7c4a9640..2bf63526b2 100644 --- a/lib/rdoc/markup/include.rb +++ b/lib/rdoc/markup/include.rb @@ -40,4 +40,3 @@ class RDoc::Markup::Include end end - diff --git a/lib/rdoc/markup/indented_paragraph.rb b/lib/rdoc/markup/indented_paragraph.rb index d42b2e52b8..992cd7cf81 100644 --- a/lib/rdoc/markup/indented_paragraph.rb +++ b/lib/rdoc/markup/indented_paragraph.rb @@ -45,4 +45,3 @@ class RDoc::Markup::IndentedParagraph < RDoc::Markup::Raw end end - diff --git a/lib/rdoc/markup/list.rb b/lib/rdoc/markup/list.rb index 05c3609202..112b7a1a86 100644 --- a/lib/rdoc/markup/list.rb +++ b/lib/rdoc/markup/list.rb @@ -99,4 +99,3 @@ class RDoc::Markup::List end end - diff --git a/lib/rdoc/markup/list_item.rb b/lib/rdoc/markup/list_item.rb index d22554ee73..0b8326a69f 100644 --- a/lib/rdoc/markup/list_item.rb +++ b/lib/rdoc/markup/list_item.rb @@ -97,4 +97,3 @@ class RDoc::Markup::ListItem end end - diff --git a/lib/rdoc/markup/paragraph.rb b/lib/rdoc/markup/paragraph.rb index a2e45ef009..21dfda007a 100644 --- a/lib/rdoc/markup/paragraph.rb +++ b/lib/rdoc/markup/paragraph.rb @@ -26,4 +26,3 @@ class RDoc::Markup::Paragraph < RDoc::Markup::Raw end end - diff --git a/lib/rdoc/markup/parser.rb b/lib/rdoc/markup/parser.rb index 1b54a519d1..9c77048591 100644 --- a/lib/rdoc/markup/parser.rb +++ b/lib/rdoc/markup/parser.rb @@ -218,7 +218,7 @@ class RDoc::Markup::Parser break if peek_token.first == :BREAK - data << ' ' if skip :NEWLINE + data << ' ' if skip :NEWLINE and /#{SPACE_SEPARATED_LETTER_CLASS}\z/o.match?(data) else unget break @@ -287,6 +287,12 @@ class RDoc::Markup::Parser line << ' ' * indent when :BREAK, :TEXT then line << data + when :BLOCKQUOTE then + line << '>>>' + peek_type, _, peek_column = peek_token + if peek_type != :NEWLINE and peek_column + line << ' ' * (peek_column - column - 3) + end else # *LIST_TOKENS list_marker = case type when :BULLET then data @@ -372,11 +378,8 @@ class RDoc::Markup::Parser unget parse_text parent, indent when :BLOCKQUOTE then - type, _, column = get - if type == :NEWLINE - type, _, column = get - end - unget if type + nil while (type, = get; type) and type != :NEWLINE + _, _, column, = peek_token bq = RDoc::Markup::BlockQuote.new p :blockquote_start => [data, column] if @debug parse bq, column @@ -417,6 +420,8 @@ class RDoc::Markup::Parser # A simple wrapper of StringScanner that is aware of the current column and lineno class MyStringScanner + # :stopdoc: + def initialize(input) @line = @column = 0 @s = StringScanner.new input @@ -453,6 +458,8 @@ class RDoc::Markup::Parser def [](i) @s[i] end + + #:startdoc: end ## @@ -544,7 +551,10 @@ class RDoc::Markup::Parser [:NOTE, @s[1], *pos] # >>> followed by end of line => :BLOCKQUOTE when @s.scan(/>>> *(\w+)?$/) then - [:BLOCKQUOTE, @s[1], *pos] + if word = @s[1] + @s.unscan(word) + end + [:BLOCKQUOTE, word, *pos] # anything else: :TEXT else @s.scan(/(.*?)( )?\r?$/) diff --git a/lib/rdoc/markup/pre_process.rb b/lib/rdoc/markup/pre_process.rb index 3080ae3578..88078c9cef 100644 --- a/lib/rdoc/markup/pre_process.rb +++ b/lib/rdoc/markup/pre_process.rb @@ -163,6 +163,8 @@ class RDoc::Markup::PreProcess if RDoc::Context === code_object then section = code_object.add_section param code_object.temporary_section = section + elsif RDoc::AnyMethod === code_object then + code_object.section_title = param end blankline # ignore category if we're not on an RDoc::Context diff --git a/lib/rdoc/markup/raw.rb b/lib/rdoc/markup/raw.rb index 85e2c8b825..a7c1c210a6 100644 --- a/lib/rdoc/markup/raw.rb +++ b/lib/rdoc/markup/raw.rb @@ -67,4 +67,3 @@ class RDoc::Markup::Raw end end - diff --git a/lib/rdoc/markup/regexp_handling.rb b/lib/rdoc/markup/regexp_handling.rb index 6ed868c2c1..c471fe73c7 100644 --- a/lib/rdoc/markup/regexp_handling.rb +++ b/lib/rdoc/markup/regexp_handling.rb @@ -38,4 +38,3 @@ class RDoc::Markup::RegexpHandling end end - diff --git a/lib/rdoc/markup/rule.rb b/lib/rdoc/markup/rule.rb index 38c1dc7f56..448148d6d1 100644 --- a/lib/rdoc/markup/rule.rb +++ b/lib/rdoc/markup/rule.rb @@ -18,4 +18,3 @@ class RDoc::Markup::Rule < Struct.new :weight end end - diff --git a/lib/rdoc/markup/table.rb b/lib/rdoc/markup/table.rb index 7bcb10aff3..27a20f073a 100644 --- a/lib/rdoc/markup/table.rb +++ b/lib/rdoc/markup/table.rb @@ -3,12 +3,21 @@ # A section of table class RDoc::Markup::Table - attr_accessor :header, :align, :body + # headers of each column + attr_accessor :header + # alignments of each column + attr_accessor :align + + # body texts of each column + attr_accessor :body + + # Creates new instance def initialize header, align, body @header, @align, @body = header, align, body end + # :stopdoc: def == other self.class == other.class and @header == other.header and @@ -20,7 +29,7 @@ class RDoc::Markup::Table visitor.accept_table @header, @body, @align end - def pretty_print q # :nodoc: + def pretty_print q q.group 2, '[Table: ', ']' do q.group 2, '[Head: ', ']' do q.seplist @header.zip(@align) do |text, align| diff --git a/lib/rdoc/markup/to_ansi.rb b/lib/rdoc/markup/to_ansi.rb index 6cc3b70e93..c3eacab21a 100644 --- a/lib/rdoc/markup/to_ansi.rb +++ b/lib/rdoc/markup/to_ansi.rb @@ -91,4 +91,3 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc end end - diff --git a/lib/rdoc/markup/to_bs.rb b/lib/rdoc/markup/to_bs.rb index f9b86487db..afd9d6e981 100644 --- a/lib/rdoc/markup/to_bs.rb +++ b/lib/rdoc/markup/to_bs.rb @@ -41,6 +41,31 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc end ## + # Prepares the visitor for consuming +list_item+ + + def accept_list_item_start list_item + type = @list_type.last + + case type + when :NOTE, :LABEL then + bullets = Array(list_item.label).map do |label| + attributes(label).strip + end.join "\n" + + bullets << ":\n" unless bullets.empty? + + @prefix = ' ' * @indent + @indent += 2 + @prefix << bullets + (' ' * @indent) + else + bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.' + @prefix = (' ' * @indent) + bullet.ljust(bullet.length + 1) + width = bullet.length + 1 + @indent += width + end + end + + ## # Turns on or off regexp handling for +convert_string+ def annotate tag diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index d3bb8af835..91cadf9d16 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'cgi' +require 'cgi/util' ## # Outputs RDoc markup as HTML. @@ -61,12 +61,15 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter # # These methods are used by regexp handling markup added by RDoc::Markup#add_regexp_handling. + # :nodoc: + URL_CHARACTERS_REGEXP_STR = /[A-Za-z0-9\-._~:\/\?#\[\]@!$&'\(\)*+,;%=]/.source + ## # Adds regexp handlings. def init_regexp_handlings # external links - @markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/, + @markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)#{URL_CHARACTERS_REGEXP_STR}+\w/, :HYPERLINK) init_link_notation_regexp_handlings end @@ -82,7 +85,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter def handle_RDOCLINK url # :nodoc: case url when /^rdoc-ref:/ - $' + CGI.escapeHTML($') when /^rdoc-label:/ text = $' @@ -93,13 +96,11 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter else text end - gen_url url, text + gen_url CGI.escapeHTML(url), CGI.escapeHTML(text) when /^rdoc-image:/ - "<img src=\"#{$'}\">" - else - url =~ /\Ardoc-[a-z]+:/ - - $' + %[<img src=\"#{CGI.escapeHTML($')}\">] + when /\Ardoc-[a-z]+:/ + CGI.escapeHTML($') end end @@ -123,7 +124,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter # Reference to a local file relative to the output directory. def handle_regexp_HYPERLINK(target) - url = target.text + url = CGI.escapeHTML(target.text) gen_url url, url end @@ -152,9 +153,13 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter text =~ /^\{(.*)\}\[(.*?)\]$/ or text =~ /^(\S+)\[(.*?)\]$/ label = $1 - url = $2 + url = CGI.escapeHTML($2) - label = handle_RDOCLINK label if /^rdoc-image:/ =~ label + if /^rdoc-image:/ =~ label + label = handle_RDOCLINK(label) + else + label = CGI.escapeHTML(label) + end gen_url url, label end @@ -198,7 +203,9 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter def accept_paragraph paragraph @res << "\n<p>" text = paragraph.text @hard_break - text = text.gsub(/\r?\n/, ' ') + text = text.gsub(/(#{SPACE_SEPARATED_LETTER_CLASS})?\K\r?\n(?=(?(1)(#{SPACE_SEPARATED_LETTER_CLASS})?))/o) { + defined?($2) && ' ' + } @res << to_html(text) @res << "</p>\n" end @@ -322,7 +329,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter header.zip(aligns) do |text, align| @res << '<th' @res << ' align="' << align << '"' if align - @res << '>' << CGI.escapeHTML(text) << "</th>\n" + @res << '>' << to_html(text) << "</th>\n" end @res << "</tr>\n</thead>\n<tbody>\n" body.each do |row| @@ -330,7 +337,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter row.zip(aligns) do |text, align| @res << '<td' @res << ' align="' << align << '"' if align - @res << '>' << CGI.escapeHTML(text) << "</td>\n" + @res << '>' << to_html(text) << "</td>\n" end @res << "</tr>\n" end @@ -426,7 +433,9 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter def parseable? text verbose, $VERBOSE = $VERBOSE, nil - eval("BEGIN {return true}\n#{text}") + catch(:valid) do + eval("BEGIN { throw :valid, true }\n#{text}") + end rescue SyntaxError false ensure @@ -441,4 +450,3 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter end end - diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb index a9fd09df41..9b5de62fd6 100644 --- a/lib/rdoc/markup/to_html_crossref.rb +++ b/lib/rdoc/markup/to_html_crossref.rb @@ -42,6 +42,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml @cross_reference = RDoc::CrossReference.new @context end + # :nodoc: def init_link_notation_regexp_handlings add_regexp_handling_RDOCLINK @@ -62,8 +63,8 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml name = name[1..-1] unless @show_hash if name[0, 1] == '#' - if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])@/ - text ||= "#{CGI.unescape $'} at <code>#{$1}</code>" + if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])?@/ + text ||= [CGI.unescape($'), (" at <code>#{$1}</code>" if $~.begin(1))].join("") code = false else text ||= name @@ -138,39 +139,37 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml # Creates an HTML link to +name+ with the given +text+. def link name, text, code = true - if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])@/ + if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])?@/ name = $1 label = $' end - ref = @cross_reference.resolve name, text + ref = @cross_reference.resolve name, text if name case ref when String then ref else - path = ref.as_href @from_path + path = ref ? ref.as_href(@from_path) : +"" if code and RDoc::CodeObject === ref and !(RDoc::TopLevel === ref) text = "<code>#{CGI.escapeHTML text}</code>" end - if path =~ /#/ then - path << "-label-#{label}" - elsif ref.sections and - ref.sections.any? { |section| label == section.title } then - path << "##{label}" - else - if ref.respond_to?(:aref) + if label + if path =~ /#/ + path << "-label-#{label}" + elsif ref&.sections&.any? { |section| label == section.title } + path << "##{label}" + elsif ref.respond_to?(:aref) path << "##{ref.aref}-label-#{label}" else path << "#label-#{label}" end - end if label + end "<a href=\"#{path}\">#{text}</a>" end end end - diff --git a/lib/rdoc/markup/to_html_snippet.rb b/lib/rdoc/markup/to_html_snippet.rb index 4eb36592b7..f471395a3a 100644 --- a/lib/rdoc/markup/to_html_snippet.rb +++ b/lib/rdoc/markup/to_html_snippet.rb @@ -66,6 +66,9 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml alias accept_rule ignore + ## + # Adds +paragraph+ to the output + def accept_paragraph paragraph para = @in_list_entry.last || "<p>" @@ -282,4 +285,3 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml end end - diff --git a/lib/rdoc/markup/to_joined_paragraph.rb b/lib/rdoc/markup/to_joined_paragraph.rb index 46e07c94ad..31cbe0853c 100644 --- a/lib/rdoc/markup/to_joined_paragraph.rb +++ b/lib/rdoc/markup/to_joined_paragraph.rb @@ -25,9 +25,9 @@ class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter def accept_paragraph paragraph parts = paragraph.parts.chunk do |part| String === part - end.map do |string, chunk| + end.flat_map do |string, chunk| string ? chunk.join.rstrip : chunk - end.flatten + end paragraph.parts.replace parts end @@ -44,4 +44,3 @@ class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter alias accept_table ignore end - diff --git a/lib/rdoc/markup/to_label.rb b/lib/rdoc/markup/to_label.rb index 3d95ccc2e2..cf808364e9 100644 --- a/lib/rdoc/markup/to_label.rb +++ b/lib/rdoc/markup/to_label.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'cgi' +require 'cgi/util' ## # Creates HTML-safe labels suitable for use in id attributes. Tidylinks are @@ -72,4 +72,3 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter alias start_accepting ignore end - diff --git a/lib/rdoc/markup/to_markdown.rb b/lib/rdoc/markup/to_markdown.rb index 3ee48becb0..b915fab60b 100644 --- a/lib/rdoc/markup/to_markdown.rb +++ b/lib/rdoc/markup/to_markdown.rb @@ -45,8 +45,6 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc # Finishes consumption of `list` def accept_list_end list - @res << "\n" - super end @@ -60,6 +58,8 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc when :NOTE, :LABEL then use_prefix + @res << "\n" + 4 else @list_index[-1] = @list_index.last.succ @@ -81,11 +81,11 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc attributes(label).strip end.join "\n" - bullets << "\n:" + bullets << "\n" unless bullets.empty? @prefix = ' ' * @indent @indent += 4 - @prefix << bullets + (' ' * (@indent - 1)) + @prefix << bullets << ":" << (' ' * (@indent - 1)) else bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.' @prefix = (' ' * @indent) + bullet.ljust(4) @@ -189,4 +189,3 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc end end - diff --git a/lib/rdoc/markup/to_rdoc.rb b/lib/rdoc/markup/to_rdoc.rb index 3cdf4fd08b..88234f5096 100644 --- a/lib/rdoc/markup/to_rdoc.rb +++ b/lib/rdoc/markup/to_rdoc.rb @@ -145,11 +145,19 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter case type when :NOTE, :LABEL then - bullets = Array(list_item.label).map do |label| + stripped_labels = Array(list_item.label).map do |label| attributes(label).strip - end.join "\n" + end + + bullets = case type + when :NOTE + stripped_labels.map { |b| "#{b}::" } + when :LABEL + stripped_labels.map { |b| "[#{b}]" } + end - bullets << ":\n" unless bullets.empty? + bullets = bullets.join("\n") + bullets << "\n" unless stripped_labels.empty? @prefix = ' ' * @indent @indent += 2 @@ -330,33 +338,15 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter 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" + text.scan(/\G(?:([^ \n]{#{text_len}})(?=[^ \n])|(.{1,#{text_len}})(?:[ \n]|\z))/) do + @res << prefix << ($1 || $2) << "\n" + prefix = next_prefix end end end - diff --git a/lib/rdoc/markup/to_table_of_contents.rb b/lib/rdoc/markup/to_table_of_contents.rb index eb8e8faa16..e5b8225ba3 100644 --- a/lib/rdoc/markup/to_table_of_contents.rb +++ b/lib/rdoc/markup/to_table_of_contents.rb @@ -86,4 +86,3 @@ class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter # :startdoc: end - diff --git a/lib/rdoc/markup/to_test.rb b/lib/rdoc/markup/to_test.rb index 61d3cffaf0..30113da561 100644 --- a/lib/rdoc/markup/to_test.rb +++ b/lib/rdoc/markup/to_test.rb @@ -67,4 +67,3 @@ class RDoc::Markup::ToTest < RDoc::Markup::Formatter # :startdoc: end - diff --git a/lib/rdoc/markup/to_tt_only.rb b/lib/rdoc/markup/to_tt_only.rb index 9235d33f04..9ac14ed235 100644 --- a/lib/rdoc/markup/to_tt_only.rb +++ b/lib/rdoc/markup/to_tt_only.rb @@ -118,4 +118,3 @@ class RDoc::Markup::ToTtOnly < RDoc::Markup::Formatter end end - diff --git a/lib/rdoc/markup/verbatim.rb b/lib/rdoc/markup/verbatim.rb index 7f1bc29a09..f51c2cfa14 100644 --- a/lib/rdoc/markup/verbatim.rb +++ b/lib/rdoc/markup/verbatim.rb @@ -81,4 +81,3 @@ class RDoc::Markup::Verbatim < RDoc::Markup::Raw end end - |