Skip to content

Commit cfce04e

Browse files
authored
Merge pull request #831 from nobu/smart-squote
Fix smart single quote
2 parents 2f7dfec + 6ed889a commit cfce04e

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/rdoc/text.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,18 @@ def to_html text
237237
when s.scan(/``/) then # backtick double quote
238238
html << encoded[:open_dquote]
239239
after_word = nil
240-
when s.scan(/''/) then # tick double quote
240+
when s.scan(/(?:&#39;|'){2}/) then # tick double quote
241241
html << encoded[:close_dquote]
242242
after_word = nil
243-
when s.scan(/'/) then # single quote
243+
when s.scan(/`/) then # backtick
244+
if insquotes or after_word
245+
html << '`'
246+
after_word = false
247+
else
248+
html << encoded[:open_squote]
249+
insquotes = true
250+
end
251+
when s.scan(/&#39;|'/) then # single quote
244252
if insquotes
245253
html << encoded[:close_squote]
246254
insquotes = false

test/rdoc/test_rdoc_markup_to_html.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ def test_convert_with_exclude_tag
712712

713713
def test_convert_underscore_adjacent_to_code
714714
assert_equal "\n<p><code>aaa</code>_</p>\n", @to.convert(%q{+aaa+_})
715-
assert_equal "\n<p>`<code>i386-mswin32_</code><em>MSRTVERSION</em>&#39;</p>\n", @to.convert(%q{`+i386-mswin32_+_MSRTVERSION_'})
715+
assert_equal "\n<p>\u{2018}<code>i386-mswin32_</code><em>MSRTVERSION</em>\u{2019}</p>\n", @to.convert(%q{`+i386-mswin32_+_MSRTVERSION_'})
716716
end
717717

718718
def test_gen_url

test/rdoc/test_rdoc_text.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,13 @@ def test_to_html_apostrophe
485485
assert_equal '‘a’ ‘', to_html("'a' '")
486486
end
487487

488+
def test_to_html_apostrophe_entity
489+
assert_equal '‘a', to_html("&#39;a")
490+
assert_equal 'a’', to_html("a&#39;")
491+
492+
assert_equal '‘a’ ‘', to_html("&#39;a&#39; &#39;")
493+
end
494+
488495
def test_to_html_backslash
489496
assert_equal 'S', to_html('\\S')
490497
end
@@ -507,6 +514,7 @@ def test_to_html_dash
507514
def test_to_html_double_backtick
508515
assert_equal '“a', to_html('``a')
509516
assert_equal '“a“', to_html('``a``')
517+
assert_equal '“a”', to_html("``a''")
510518
end
511519

512520
def test_to_html_double_quote

0 commit comments

Comments
 (0)