def f(...); end` and `(c) in `` will be wrongly converted.
- to_html_characters(handle_inline(item))
+ handle_inline(item)
end
end
diff --git a/lib/rdoc/markup/to_html_snippet.rb b/lib/rdoc/markup/to_html_snippet.rb
index 52cc4543f3..0f485cae8e 100644
--- a/lib/rdoc/markup/to_html_snippet.rb
+++ b/lib/rdoc/markup/to_html_snippet.rb
@@ -109,7 +109,7 @@ def accept_verbatim(verbatim)
input = verbatim.text.rstrip
text = truncate(input, @character_limit - @characters)
@characters += input.length
- text << ' ...' unless text == input
+ text << " #{TO_HTML_CHARACTERS[text.encoding][:ellipsis]}" unless text == input
super RDoc::Markup::Verbatim.new text
@@ -262,14 +262,14 @@ def handle_inline(text)
return ['', 0] if limit <= 0
@inline_character_limit = limit
res = super
- res << ' ...' if @inline_character_limit <= 0
+ res << " #{TO_HTML_CHARACTERS[text.encoding][:ellipsis]}" if @inline_character_limit <= 0
@characters += limit - @inline_character_limit
res
end
def to_html(item)
throw :done if @characters >= @character_limit
- to_html_characters(handle_inline(item))
+ handle_inline(item)
end
##
diff --git a/lib/rdoc/text.rb b/lib/rdoc/text.rb
index 94c84037c8..6d28a196ef 100644
--- a/lib/rdoc/text.rb
+++ b/lib/rdoc/text.rb
@@ -29,34 +29,6 @@ module RDoc::Text
MARKUP_FORMAT.default = RDoc::Markup
- ##
- # Maps an encoding to a Hash of characters properly transcoded for that
- # encoding.
- #
- # See also encode_fallback.
-
- TO_HTML_CHARACTERS = Hash.new do |h, encoding|
- h[encoding] = {
- :close_dquote => encode_fallback('”', encoding, '"'),
- :close_squote => encode_fallback('’', encoding, '\''),
- :copyright => encode_fallback('©', encoding, '(c)'),
- :ellipsis => encode_fallback('…', encoding, '...'),
- :em_dash => encode_fallback('—', encoding, '---'),
- :en_dash => encode_fallback('–', encoding, '--'),
- :open_dquote => encode_fallback('“', encoding, '"'),
- :open_squote => encode_fallback('‘', encoding, '\''),
- :trademark => encode_fallback('®', encoding, '(r)'),
- }
- end
-
- ##
- # Transcodes +character+ to +encoding+ with a +fallback+ character.
-
- def self.encode_fallback(character, encoding, fallback)
- character.encode(encoding, :fallback => { character => fallback },
- :undef => :replace, :replace => fallback)
- end
-
##
# Expands tab characters in +text+ to eight spaces
@@ -193,95 +165,6 @@ def strip_stars(text)
text.gsub(/^\s+$/, empty)
end
- def to_html(text)
- to_html_characters(text)
- end
-
- ##
- # Converts ampersand, dashes, ellipsis, quotes, copyright and registered
- # trademark symbols in +text+ to properly encoded characters.
-
- def to_html_characters(text)
- html = (''.encode text.encoding).dup
-
- encoded = RDoc::Text::TO_HTML_CHARACTERS[text.encoding]
-
- s = StringScanner.new text
- insquotes = false
- indquotes = false
- after_word = nil
-
- until s.eos? do
- case
- when s.scan(/<(tt|code)>.*?<\/\1>/) then # skip contents of tt
- html << s.matched
- when s.scan(/<(tt|code)>.*?/) then
- warn "mismatched <#{s[1]}> tag" # TODO signal file/line
- html << s.matched
- when s.scan(/<[^>]+\/?s*>/) then # skip HTML tags
- html << s.matched
- when s.scan(/\.\.\.(\.?)/) then
- html << s[1] << encoded[:ellipsis]
- after_word = nil
- when s.scan(/\(c\)/i) then
- html << encoded[:copyright]
- after_word = nil
- when s.scan(/\(r\)/i) then
- html << encoded[:trademark]
- after_word = nil
- when s.scan(/---/) then
- html << encoded[:em_dash]
- after_word = nil
- when s.scan(/--/) then
- html << encoded[:en_dash]
- after_word = nil
- when s.scan(/"|"/) then
- html << encoded[indquotes ? :close_dquote : :open_dquote]
- indquotes = !indquotes
- after_word = nil
- when s.scan(/``/) then # backtick double quote
- html << encoded[:open_dquote]
- after_word = nil
- when s.scan(/(?:'|'){2}/) then # tick double quote
- html << encoded[:close_dquote]
- after_word = nil
- when s.scan(/`/) then # backtick
- if insquotes or after_word
- html << '`'
- after_word = false
- else
- html << encoded[:open_squote]
- insquotes = true
- end
- when s.scan(/'|'/) then # single quote
- if insquotes
- html << encoded[:close_squote]
- insquotes = false
- elsif after_word
- # Mary's dog, my parents' house: do not start paired quotes
- html << encoded[:close_squote]
- else
- html << encoded[:open_squote]
- insquotes = true
- end
-
- after_word = nil
- else # advance to the next potentially significant character
- match = s.scan(/.+?(?=[<\\.("'`&-])/) #"
-
- if match then
- html << match
- after_word = match =~ /\w$/
- else
- html << s.rest
- break
- end
- end
- end
-
- html
- end
-
##
# Wraps +txt+ to +line_len+
diff --git a/test/rdoc/markup/to_html_snippet_test.rb b/test/rdoc/markup/to_html_snippet_test.rb
index ce9118a18c..f9bf2fb890 100644
--- a/test/rdoc/markup/to_html_snippet_test.rb
+++ b/test/rdoc/markup/to_html_snippet_test.rb
@@ -543,7 +543,7 @@ def test_convert_limit_verbatim
Hello There
This is some text, it will be cut off after 100 characters -
This one is cut off in this verbatim ...+
This one is cut off in this verbatim …EXPECTED actual = @to.convert rdoc diff --git a/test/rdoc/markup/to_html_test.rb b/test/rdoc/markup/to_html_test.rb index 459bcb140e..05a42c95d6 100644 --- a/test/rdoc/markup/to_html_test.rb +++ b/test/rdoc/markup/to_html_test.rb @@ -669,6 +669,51 @@ def test_convert_string assert_equal '<>', @to.convert_string('<>') end + def test_self_converter_encode_fallback + assert_equal '…', + RDoc::Markup::ToHtml::encode_fallback('…', Encoding::UTF_8, '...') + assert_equal '...', + RDoc::Markup::ToHtml::encode_fallback('…', Encoding::US_ASCII, '...') + end + + def test_convert_HTML_CHARACTER + result = @to.convert "(c)(r)(C)(R)...--....---``''" + assert_equal "\n
©®©®…–.…—“”
\n", result + + result = @to.convert "(c)(r)(C)(R)...--....---``''" + assert_equal "\n(c)(r)(C)(R)...--....---``''
#{expected}
\n", result + end + + def test_convert_QUOTE_dquote + result = @to.convert '"This is a +quoted+ string." and "another"' + assert_equal "\n“This is a quoted string.” and “another”
‘quote’ ‘1+2’. I’m ‘RDoc’
\n", result + end + + def test_convert_QUOTE_backtick + result = @to.convert "This is `quote' and this is `code`" + assert_equal "\nThis is ‘quote’ and this is code