Skip to content

Commit

Permalink
lib/rdoc/markup/to_label.rb (convert): Make labels cross-browser comp…
Browse files Browse the repository at this point in the history
…atible.

Percent-encoded URL fragments prevent Firefox from jumping to their respective anchors. Wikipedia (MediaWiki) does something similar, with `.` instead of `-`.

There's precedent in `RDoc::{Alias,MethodAttr}#html_name` (54dbcf7) and `RDoc::Context::Section#aref` (431baa1). This breaks backwards-compatibility, though.
  • Loading branch information
blackwinter committed Oct 17, 2014
1 parent 21b241a commit 463019b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/rdoc/markup/to_label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def initialize markup = nil
def convert text
label = convert_flow @am.flow text

CGI.escape label
CGI.escape(label).gsub('%', '-').sub(/^-/, '')
end

##
Expand Down
8 changes: 4 additions & 4 deletions test/test_rdoc_markup_heading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ def setup
end

def test_aref
assert_equal 'label-Hello+Friend%21', @h.aref
assert_equal 'label-Hello+Friend-21', @h.aref
end

def test_label
assert_equal 'label-Hello+Friend%21', @h.label
assert_equal 'label-Hello+Friend%21', @h.label(nil)
assert_equal 'label-Hello+Friend-21', @h.label
assert_equal 'label-Hello+Friend-21', @h.label(nil)

context = RDoc::NormalClass.new 'Foo'

assert_equal 'class-Foo-label-Hello+Friend%21', @h.label(context)
assert_equal 'class-Foo-label-Hello+Friend-21', @h.label(context)
end

def test_plain_html
Expand Down
8 changes: 4 additions & 4 deletions test/test_rdoc_markup_to_label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def test_convert_crossref
assert_equal 'some_method', @to.convert('some_method')
assert_equal 'some_method', @to.convert('\\some_method')

assert_equal '%23some_method', @to.convert('#some_method')
assert_equal '%23some_method', @to.convert('\\#some_method')
assert_equal '23some_method', @to.convert('#some_method')
assert_equal '23some_method', @to.convert('\\#some_method')
end

def test_convert_em
Expand All @@ -92,11 +92,11 @@ def test_convert_em
end

def test_convert_em_dash # for HTML conversion
assert_equal '--', @to.convert('--')
assert_equal '-', @to.convert('--')
end

def test_convert_escape
assert_equal 'a+%3E+b', @to.convert('a > b')
assert_equal 'a+-3E+b', @to.convert('a > b')
end

def test_convert_tidylink
Expand Down

0 comments on commit 463019b

Please sign in to comment.