Skip to content

Commit 9b168d2

Browse files
Copilotdscho
andcommitted
Fix anchor links in documentation by stripping HTML tags
Co-authored-by: dscho <[email protected]>
1 parent 550cd41 commit 9b168d2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

script/update-docs.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
174174

175175
# HTML anchor on hdlist1 (i.e. command options)
176176
html.gsub!(/<dt class="hdlist1">(.*?)<\/dt>/) do |_m|
177-
text = $1.tr("^A-Za-z0-9-", "")
177+
text = $1.gsub(/<\/?(?:code|placeholder)>/, "").tr("^A-Za-z0-9-", "")
178178
# use txt_path for backward compatibility of already-existing
179179
# deep links shared across the interwebs.
180180
anchor = "#{txt_path}-#{text}"
@@ -465,7 +465,7 @@ def index_doc(filter_tags, doc_list, get_content)
465465
end
466466
# HTML anchor on hdlist1 (i.e. command options)
467467
html.gsub!(/<dt class="hdlist1">(.*?)<\/dt>/) do |_m|
468-
text = $1.tr("^A-Za-z0-9-", "")
468+
text = $1.gsub(/<\/?(?:code|placeholder)>/, "").tr("^A-Za-z0-9-", "")
469469
# use txt_path for backward compatibility of already-existing
470470
# deep links shared across the interwebs.
471471
anchor = "#{txt_path}-#{text}"

tests/git-scm.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,25 @@ test('manual pages', async ({ page }) => {
193193
await expect(synopsis).not.toHaveText(/git remote renom.*<ancien> <nouveau>/)
194194
})
195195

196+
test('anchor links in manual pages', async ({ page }) => {
197+
// Test that anchor links work with different formats (with or without code tags)
198+
await page.goto(`${url}docs/git-clone`)
199+
200+
// Check that old-style anchor links without code tags still work
201+
await page.goto(`${url}docs/git-clone#Documentation/git-clone.txt---recurse-submodulesltpathspecgt`)
202+
203+
// Find the element that should be highlighted/anchored to
204+
const anchoredElement = page.locator('#Documentation-git-clone\\.txt---recurse-submodulesltpathspecgt')
205+
await expect(anchoredElement).toBeVisible()
206+
207+
// Check that new-style anchor links with code tags also work
208+
await page.goto(`${url}docs/git-clone#Documentation/git-clone.txt-code--recurse-submodulesltpathspecgtcode`)
209+
210+
// Both should point to the same element (after our fix)
211+
const anchoredElementAlt = page.locator('#Documentation-git-clone\\.txt---recurse-submodulesltpathspecgt')
212+
await expect(anchoredElementAlt).toBeVisible()
213+
})
214+
196215
test('book', async ({ page }) => {
197216
await page.goto(`${url}book/`)
198217
await expect(page).toHaveURL(`${url}book/en/v2`)

0 commit comments

Comments
 (0)