diff options
Diffstat (limited to 'lib/rdoc/markup/to_html.rb')
-rw-r--r-- | lib/rdoc/markup/to_html.rb | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index 2bfabc8942..91cadf9d16 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -61,6 +61,7 @@ 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 ## @@ -84,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 = $' @@ -95,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 @@ -125,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 @@ -154,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 @@ -200,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 @@ -324,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| @@ -332,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 @@ -428,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 @@ -443,4 +450,3 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter end end - |