aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rdoc/markup/to_markdown.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rdoc/markup/to_markdown.rb')
-rw-r--r--lib/rdoc/markup/to_markdown.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/rdoc/markup/to_markdown.rb b/lib/rdoc/markup/to_markdown.rb
index e984776399..62ad3ad13e 100644
--- a/lib/rdoc/markup/to_markdown.rb
+++ b/lib/rdoc/markup/to_markdown.rb
@@ -18,6 +18,9 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
@headings[5] = ['##### ', '']
@headings[6] = ['###### ', '']
+ add_special_RDOCLINK
+ add_special_TIDYLINK
+
@hard_break = " \n"
end
@@ -130,5 +133,57 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
@res << "\n" unless @res =~ /\n\z/
end
+ ##
+ # Creates a Markdown-style URL from +url+ with +text+.
+
+ def gen_url url, text
+ scheme, url, = parse_url url
+
+ "[#{text.sub(%r{^#{scheme}:/*}i, '')}](#{url})"
+ end
+
+ ##
+ # Handles <tt>rdoc-</tt> type links for footnotes.
+
+ def handle_rdoc_link url
+ case url
+ when /\Ardoc-ref:/ then
+ $'
+ when /\Ardoc-label:footmark-(\d+)/ then
+ "[^#{$1}]:"
+ when /\Ardoc-label:foottext-(\d+)/ then
+ "[^#{$1}]"
+ when /\Ardoc-label:label-/ then
+ gen_url url, $'
+ when /\Ardoc-[a-z]+:/ then
+ $'
+ end
+ end
+
+ ##
+ # Converts the RDoc markup tidylink into a Markdown.style link.
+
+ def handle_special_TIDYLINK special
+ text = special.text
+
+ return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
+
+ label = $1
+ url = $2
+
+ if url =~ /^rdoc-label:foot/ then
+ handle_rdoc_link url
+ else
+ gen_url url, label
+ end
+ end
+
+ ##
+ # Converts the rdoc-...: links into a Markdown.style links.
+
+ def handle_special_RDOCLINK special
+ handle_rdoc_link special.text
+ end
+
end