Skip to content

Use the method aref for source code ids - #1887

Open
sourya2704 wants to merge 1 commit into
ruby:masterfrom
sourya2704:fix-duplicate-source-ids
Open

sourya2704 wants to merge 1 commit into
ruby:masterfrom
sourya2704:fix-duplicate-source-ids

Conversation

@sourya2704

Copy link
Copy Markdown

Fixes #1884.

Each method's source code block has the id "#{method.html_name}-source". html_name is just the escaped method name, so a class with a class method and an instance method of the same name gets the same id twice. On https://docs.ruby-lang.org/en/master/Date.html, Date.httpdate and Date#httpdate both have:

<div class="method-source-code" id="httpdate-source">

This uses method.aref instead, which already has the c/i part used by the method's own anchor:

<div class="method-source-code" id="method-c-httpdate-source">
<div class="method-source-code" id="method-i-httpdate-source">

The change is in both the darkfish and aliki class.rhtml. Nothing refers to these ids: the source toggle in darkfish.js and aliki.js finds the block with .method-source-code inside the .method-detail, so the toggle works as before.

The new test in darkfish_test.rb and aliki_test.rb generates a class with .parse and #parse, both with source code. It checks for both ids and that the page has no duplicate ids. It fails on both themes without the fix.

I also generated docs for a sample class and lib/rdoc/markup with both themes and scanned every page for duplicate ids. Apart from the ones fixed in #1886, these source ids were the only duplicates.

bundle exec rake normal_test and RuboCop on the changed tests pass.

The source code block of a method had the id "#{html_name}-source".
html_name doesn't include whether the method is a class or instance
method, so a class with both, like Date.httpdate and Date#httpdate,
had two elements with the id httpdate-source.

Use "#{aref}-source" instead, which gives method-c-httpdate-source and
method-i-httpdate-source. Nothing refers to these ids: the source toggle
finds the block by its class.

Fixes ruby#1884
@BurdetteLamar

Copy link
Copy Markdown
Member

This and the two immediately preceding PRs offend the relevant HTML standard, which requires an ID attribute to be unique and non-empty.

I can't mark these as bugs, though they are.

@st0012, Can these be approved and merged soon?

Thanks,
Burdette

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Page has duplicate id attribute values

2 participants