From df7dac9174a31e71b58be6184e23bfe6b742a494 Mon Sep 17 00:00:00 2001 From: drbrain Date: Wed, 18 Sep 2013 23:33:36 +0000 Subject: * lib/rdoc: Update to RDoc 4.1.0.preview.1 RDoc 4.1.0 contains a number of enhancements including a new default style and accessibility support. You can see the changelog here: https://github.com/rdoc/rdoc/blob/v4.1.0.preview.1/History.rdoc * test/rdoc: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/markup/attribute_manager.rb | 5 +- lib/rdoc/markup/formatter.rb | 6 +- lib/rdoc/markup/heading.rb | 13 +++++ lib/rdoc/markup/parser.rb | 9 ++- lib/rdoc/markup/pre_process.rb | 2 +- lib/rdoc/markup/to_html.rb | 105 +++++++++++++++++++++-------------- lib/rdoc/markup/to_html_crossref.rb | 3 + lib/rdoc/markup/to_markdown.rb | 12 ++-- 8 files changed, 102 insertions(+), 53 deletions(-) (limited to 'lib/rdoc/markup') diff --git a/lib/rdoc/markup/attribute_manager.rb b/lib/rdoc/markup/attribute_manager.rb index 7ee6f423d6..c5a50d519c 100644 --- a/lib/rdoc/markup/attribute_manager.rb +++ b/lib/rdoc/markup/attribute_manager.rb @@ -186,8 +186,9 @@ class RDoc::Markup::AttributeManager # protect __send__, __FILE__, etc. @str.gsub!(/__([a-z]+)__/i, "_#{PROTECT_ATTR}_#{PROTECT_ATTR}\\1_#{PROTECT_ATTR}_#{PROTECT_ATTR}") - @str.gsub!(/\\([#{Regexp.escape @protectable.join('')}])/, - "\\1#{PROTECT_ATTR}") + @str.gsub!(/(\A|[^\\])\\([#{Regexp.escape @protectable.join}])/m, + "\\1\\2#{PROTECT_ATTR}") + @str.gsub!(/\\(\\[#{Regexp.escape @protectable.join}])/m, "\\1") end ## diff --git a/lib/rdoc/markup/formatter.rb b/lib/rdoc/markup/formatter.rb index b668746c7a..7661c95239 100644 --- a/lib/rdoc/markup/formatter.rb +++ b/lib/rdoc/markup/formatter.rb @@ -80,7 +80,7 @@ class RDoc::Markup::Formatter # Adds a special for links of the form rdoc-...: def add_special_RDOCLINK - @markup.add_special(/rdoc-[a-z]+:\S+/, :RDOCLINK) + @markup.add_special(/rdoc-[a-z]+:[^\s\]]+/, :RDOCLINK) end ## @@ -88,7 +88,7 @@ class RDoc::Markup::Formatter def add_special_TIDYLINK @markup.add_special(/(?: - \{.*?\} | # multi-word label + \{.*?\} | # multi-word label \b[^\s{}]+? # single-word label ) @@ -239,7 +239,7 @@ class RDoc::Markup::Formatter else scheme = 'http' path = url - url = "http://#{url}" + url = url end if scheme == 'link' then diff --git a/lib/rdoc/markup/heading.rb b/lib/rdoc/markup/heading.rb index b1f372222f..535e310e54 100644 --- a/lib/rdoc/markup/heading.rb +++ b/lib/rdoc/markup/heading.rb @@ -47,6 +47,19 @@ RDoc::Markup::Heading = "label-#{self.class.to_label.convert text.dup}" end + ## + # Creates a fully-qualified label which will include the label from + # +context+. This helps keep ids unique in HTML. + + def label context = nil + label = aref + + label = [context.aref, label].compact.join '-' if + context and context.respond_to? :aref + + label + end + ## # HTML markup of the text of this label without the surrounding header # element. diff --git a/lib/rdoc/markup/parser.rb b/lib/rdoc/markup/parser.rb index 3fce2b4c3b..4d0cf1127e 100644 --- a/lib/rdoc/markup/parser.rb +++ b/lib/rdoc/markup/parser.rb @@ -389,7 +389,7 @@ class RDoc::Markup::Parser skip :NEWLINE when :TEXT then unget - parent << build_paragraph(indent) + parse_text parent, indent when *LIST_TOKENS then unget parent << build_list(indent) @@ -405,6 +405,13 @@ class RDoc::Markup::Parser end + ## + # Small hook that is overridden by RDoc::TomDoc + + def parse_text parent, indent # :nodoc: + parent << build_paragraph(indent) + end + ## # Returns the next token on the stream without modifying the stream diff --git a/lib/rdoc/markup/pre_process.rb b/lib/rdoc/markup/pre_process.rb index 6024edcd27..01fb293462 100644 --- a/lib/rdoc/markup/pre_process.rb +++ b/lib/rdoc/markup/pre_process.rb @@ -151,7 +151,7 @@ class RDoc::Markup::PreProcess case directive when 'arg', 'args' then - return blankline unless code_object + return "#{prefix}:#{directive}: #{param}\n" unless code_object code_object.params = param diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index 37b9492e23..823b023e72 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -65,6 +65,30 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter # # These methods handle special markup added by RDoc::Markup#add_special. + def handle_RDOCLINK url # :nodoc: + case url + when /^rdoc-ref:/ + $' + when /^rdoc-label:/ + text = $' + + text = case text + when /\Alabel-/ then $' + when /\Afootmark-/ then $' + when /\Afoottext-/ then $' + else text + end + + gen_url url, text + when /^rdoc-image:/ + "" + else + url =~ /\Ardoc-[a-z]+:/ + + $' + end + end + ## # +special+ is a
@@ -100,27 +124,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter # when creating a link. All other contents will be linked verbatim. def handle_special_RDOCLINK special - url = special.text - - case url - when /\Ardoc-ref:/ - $' - when /\Ardoc-label:/ - text = $' - - text = case text - when /\Alabel-/ then $' - when /\Afootmark-/ then "^#{$'}" - when /\Afoottext-/ then "*#{$'}" - else text - end - - gen_url url, text - else - url =~ /\Ardoc-[a-z]+:/ - - $' - end + handle_RDOCLINK special.text end ## @@ -130,10 +134,14 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter def handle_special_TIDYLINK(special) text = special.text - return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/ + return text unless + text =~ /^\{(.*)\}\[(.*?)\]$/ or text =~ /^(\S+)\[(.*?)\]$/ label = $1 url = $2 + + label = handle_RDOCLINK label if /^rdoc-image:/ =~ label + gen_url url, label end @@ -176,6 +184,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter def accept_paragraph paragraph @res << "\n

" text = paragraph.text @hard_break + text = text.gsub(/\r?\n/, ' ') @res << wrap(to_html(text)) @res << "

\n" end @@ -186,28 +195,33 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter def accept_verbatim verbatim text = verbatim.text.rstrip - @res << if verbatim.ruby? or parseable? text then - begin - tokens = RDoc::RubyLex.tokenize text, @options + klass = nil - html = RDoc::TokenStream.to_html tokens + content = if verbatim.ruby? or parseable? text then + begin + tokens = RDoc::RubyLex.tokenize text, @options + klass = ' class="ruby"' - "\n
#{html}
\n" - rescue RDoc::RubyLex::Error - "\n
#{CGI.escapeHTML text}
\n" + RDoc::TokenStream.to_html tokens + rescue RDoc::RubyLex::Error + CGI.escapeHTML text + end + else + CGI.escapeHTML text end - else - "\n
#{CGI.escapeHTML text}
\n" - end + + if @options.pipe then + @res << "\n
#{CGI.escapeHTML text}
\n" + else + @res << "\n#{content}\n" + end end ## # Adds +rule+ to the output - def accept_rule(rule) - size = rule.weight - size = 10 if size > 10 - @res << "
\n" + def accept_rule rule + @res << "
\n" end ## @@ -262,11 +276,13 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter def accept_heading heading level = [6, heading.level].min - label = heading.aref - label = [@code_object.aref, label].compact.join '-' if - @code_object and @code_object.respond_to? :aref + label = heading.label @code_object - @res << "\n" + @res << if @options.output_decoration + "\n" + else + "\n" + end @res << to_html(heading.text) unless @options.pipe then @res << "" @@ -302,7 +318,14 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then "" else - "#{text.sub(%r{^#{scheme}:/*}i, '')}" + text = text.sub %r%^#{scheme}:/*%i, '' + text = text.sub %r%^[*\^](\d+)$%, '\1' + + link = "#{text}" + + link = "#{link}" if /"foot/ =~ id + + link end end diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb index 405f68c14f..d27e0ab627 100644 --- a/lib/rdoc/markup/to_html_crossref.rb +++ b/lib/rdoc/markup/to_html_crossref.rb @@ -145,6 +145,9 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml if path =~ /#/ then path << "-label-#{label}" + elsif ref.sections and + ref.sections.any? { |section| label == section.title } then + path << "##{label}" else path << "#label-#{label}" end if label diff --git a/lib/rdoc/markup/to_markdown.rb b/lib/rdoc/markup/to_markdown.rb index 62ad3ad13e..d4b15bf41b 100644 --- a/lib/rdoc/markup/to_markdown.rb +++ b/lib/rdoc/markup/to_markdown.rb @@ -147,15 +147,17 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc def handle_rdoc_link url case url - when /\Ardoc-ref:/ then + when /^rdoc-ref:/ then $' - when /\Ardoc-label:footmark-(\d+)/ then + when /^rdoc-label:footmark-(\d+)/ then "[^#{$1}]:" - when /\Ardoc-label:foottext-(\d+)/ then + when /^rdoc-label:foottext-(\d+)/ then "[^#{$1}]" - when /\Ardoc-label:label-/ then + when /^rdoc-label:label-/ then gen_url url, $' - when /\Ardoc-[a-z]+:/ then + when /^rdoc-image:/ then + "![](#{$'})" + when /^rdoc-[a-z]+:/ then $' end end -- cgit v1.2.3