Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix smart single quote #831

Merged
merged 3 commits into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/rdoc/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,18 @@ def to_html text
when s.scan(/``/) then # backtick double quote
html << encoded[:open_dquote]
after_word = nil
when s.scan(/''/) then # tick double quote
when s.scan(/(?:&#39;|'){2}/) then # tick double quote
html << encoded[:close_dquote]
after_word = nil
when s.scan(/'/) then # single quote
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(/&#39;|'/) then # single quote
if insquotes
html << encoded[:close_squote]
insquotes = false
Expand Down
2 changes: 1 addition & 1 deletion test/rdoc/test_rdoc_markup_to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def test_convert_with_exclude_tag

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

def test_gen_url
Expand Down
8 changes: 8 additions & 0 deletions test/rdoc/test_rdoc_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,13 @@ def test_to_html_apostrophe
assert_equal '‘a’ ‘', to_html("'a' '")
end

def test_to_html_apostrophe_entity
assert_equal '‘a', to_html("&#39;a")
assert_equal 'a’', to_html("a&#39;")

assert_equal '‘a’ ‘', to_html("&#39;a&#39; &#39;")
end

def test_to_html_backslash
assert_equal 'S', to_html('\\S')
end
Expand All @@ -507,6 +514,7 @@ def test_to_html_dash
def test_to_html_double_backtick
assert_equal '“a', to_html('``a')
assert_equal '“a“', to_html('``a``')
assert_equal '“a”', to_html("``a''")
end

def test_to_html_double_quote
Expand Down