summaryrefslogtreecommitdiff
path: root/lib/rdoc/markup
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-18 23:33:36 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-18 23:33:36 +0000
commitdf7dac9174a31e71b58be6184e23bfe6b742a494 (patch)
tree885edf624f0e8f37014b0d937340ac1c372a0066 /lib/rdoc/markup
parentfed428007c015ac3b7f4586f2491517fafffa030 (diff)
* 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
Diffstat (limited to 'lib/rdoc/markup')
-rw-r--r--lib/rdoc/markup/attribute_manager.rb5
-rw-r--r--lib/rdoc/markup/formatter.rb6
-rw-r--r--lib/rdoc/markup/heading.rb13
-rw-r--r--lib/rdoc/markup/parser.rb9
-rw-r--r--lib/rdoc/markup/pre_process.rb2
-rw-r--r--lib/rdoc/markup/to_html.rb105
-rw-r--r--lib/rdoc/markup/to_html_crossref.rb3
-rw-r--r--lib/rdoc/markup/to_markdown.rb12
8 files changed, 102 insertions, 53 deletions
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
@@ -48,6 +48,19 @@ RDoc::Markup::Heading =
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)
@@ -406,6 +406,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
def peek_token
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:/
+ "<img src=\"#{$'}\">"
+ else
+ url =~ /\Ardoc-[a-z]+:/
+
+ $'
+ end
+ end
+
##
# +special+ is a <code><br></code>
@@ -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<p>"
text = paragraph.text @hard_break
+ text = text.gsub(/\r?\n/, ' ')
@res << wrap(to_html(text))
@res << "</p>\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<pre class=\"ruby\">#{html}</pre>\n"
- rescue RDoc::RubyLex::Error
- "\n<pre>#{CGI.escapeHTML text}</pre>\n"
+ RDoc::TokenStream.to_html tokens
+ rescue RDoc::RubyLex::Error
+ CGI.escapeHTML text
+ end
+ else
+ CGI.escapeHTML text
end
- else
- "\n<pre>#{CGI.escapeHTML text}</pre>\n"
- end
+
+ if @options.pipe then
+ @res << "\n<pre><code>#{CGI.escapeHTML text}</code></pre>\n"
+ else
+ @res << "\n<pre#{klass}>#{content}</pre>\n"
+ end
end
##
# Adds +rule+ to the output
- def accept_rule(rule)
- size = rule.weight
- size = 10 if size > 10
- @res << "<hr style=\"height: #{size}px\">\n"
+ def accept_rule rule
+ @res << "<hr>\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<h#{level} id=\"#{label}\">"
+ @res << if @options.output_decoration
+ "\n<h#{level} id=\"#{label}\">"
+ else
+ "\n<h#{level}>"
+ end
@res << to_html(heading.text)
unless @options.pipe then
@res << "<span><a href=\"##{label}\">&para;</a>"
@@ -302,7 +318,14 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
"<img src=\"#{url}\" />"
else
- "<a#{id} href=\"#{url}\">#{text.sub(%r{^#{scheme}:/*}i, '')}</a>"
+ text = text.sub %r%^#{scheme}:/*%i, ''
+ text = text.sub %r%^[*\^](\d+)$%, '\1'
+
+ link = "<a#{id} href=\"#{url}\">#{text}</a>"
+
+ link = "<sup>#{link}</sup>" 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