Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 20 additions & 2 deletions script/update-docs.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby

require "asciidoctor"
require "nokogiri"
require "octokit"
require "time"
require "digest/sha1"
Expand Down Expand Up @@ -182,7 +183,15 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
anchor += "-1" while ids.include?(anchor)
ids.add(anchor)

"<dt class=\"hdlist1\" id=\"#{anchor}\"> <a class=\"anchor\" href=\"##{anchor}\"></a>#{$1} </dt>"
clean_text = Nokogiri::HTML.parse($1).text.tr("^A-Za-z0-9-", "")
if clean_text != text
clean_anchor = "#{txt_path}-#{clean_text}"
clean_anchor += "-1" while ids.include?(clean_anchor)
ids.add(clean_anchor)
clean_anchor = "<a class=\"anchor\" href=\"##{clean_anchor}\"></a> "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dscho LOL, we did it wrong. We're adding another link with a href, while we should have added a span (or whatever) with a id :D. Can we thank Co-pilot for this nice mixup?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣 I was about to make the same remark! A patch is in making.

end

"<dt class=\"hdlist1\" id=\"#{anchor}\"> #{clean_anchor}<a class=\"anchor\" href=\"##{anchor}\"></a>#{$1} </dt>"
end
# Make links relative
html.gsub!(/(<a href=['"])\/([^'"]*)/) do |match|
Expand Down Expand Up @@ -472,7 +481,16 @@ def index_doc(filter_tags, doc_list, get_content)
# handle anchor collisions by appending -1
anchor += "-1" while ids.include?(anchor)
ids.add(anchor)
"<dt class=\"hdlist1\" id=\"#{anchor}\"> <a class=\"anchor\" href=\"##{anchor}\"></a>#{$1} </dt>"

clean_text = Nokogiri::HTML.parse($1).text.tr("^A-Za-z0-9-", "")
if clean_text != text
clean_anchor = "#{txt_path}-#{clean_text}"
clean_anchor += "-1" while ids.include?(clean_anchor)
ids.add(clean_anchor)
clean_anchor = "<a class=\"anchor\" href=\"##{clean_anchor}\"></a> "
end

"<dt class=\"hdlist1\" id=\"#{anchor}\"> #{clean_anchor}<a class=\"anchor\" href=\"##{anchor}\"></a>#{$1} </dt>"
end
# Make links relative
html.gsub!(/(<a href=['"])\/([^'"]*)/) do |relurl|
Expand Down
10 changes: 10 additions & 0 deletions tests/git-scm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ test('manual pages', async ({ page }) => {
await expect(synopsis).not.toHaveText(/git remote renom.*<ancien> <nouveau>/)
})

test('anchor links in manual pages', async ({ page }) => {
// Test that anchor links work without HTML tags
const anchor = '#Documentation/git-clone.txt---recurse-submodulesltpathspecgt'
await page.goto(`${url}docs/git-clone${anchor}`)

// Find the anchored element that should be scrolled into view
const anchoredElement = await page.getByText(/^--recurse-submodules.*pathspec/)
await expect(anchoredElement).toBeVisible()
})

test('book', async ({ page }) => {
await page.goto(`${url}book/`)
await expect(page).toHaveURL(`${url}book/en/v2`)
Expand Down