Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/git/git-scm.com.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Saccone <samccone@sams-mac-studio.lan>2022-09-11 02:22:42 +0300
committerSam Saccone <samccone@sams-mac-studio.lan>2022-09-11 23:41:43 +0300
commit81d803ed8f0c36d7d6abf1845bb43d072603206f (patch)
tree941f46e6188a6eafdda70700d107d07610daec90
parentde8814ad3268b872b9ab46d20420912c1e9b4791 (diff)
Handle colliding anchors in documentation pages.
Add -1 to the anchor until we are no longer colliding with existing known anchors on the page. BUG=#1729
-rw-r--r--lib/tasks/index.rake14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/tasks/index.rake b/lib/tasks/index.rake
index a6954e56..dc47a9ce 100644
--- a/lib/tasks/index.rake
+++ b/lib/tasks/index.rake
@@ -4,6 +4,7 @@ require "asciidoctor"
require "octokit"
require "time"
require "digest/sha1"
+require "set"
def make_asciidoc(content)
Asciidoctor::Document.new(content,
@@ -75,6 +76,7 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
doc_files.each do |entry|
full_path, sha = entry
+ ids = Set.new([])
lang = File.dirname(full_path)
path = File.basename(full_path, ".txt")
#next if doc_limit && path !~ /#{doc_limit}/
@@ -100,6 +102,12 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
html.gsub!(/<dt class="hdlist1">(.*?)<\/dt>/) do |m|
text = $1.tr("^A-Za-z0-9-", "")
anchor = "#{path}-#{text}"
+ # handle anchor collisions by appending -1
+ while ids.include?(anchor)
+ anchor += "-1"
+ end
+ ids.add(anchor)
+
"<dt class=\"hdlist1\" id=\"#{anchor}\"> <a class=\"anchor\" href=\"##{anchor}\"></a>#{$1} </dt>"
end
doc.plain = asciidoc.source
@@ -244,6 +252,7 @@ def index_doc(filter_tags, doc_list, get_content)
doc_files.each do |entry|
path, sha = entry
+ ids = Set.new([])
docname = File.basename(path, ".txt")
next if doc_limit && path !~ /#{doc_limit}/
@@ -266,6 +275,11 @@ def index_doc(filter_tags, doc_list, get_content)
html.gsub!(/<dt class="hdlist1">(.*?)<\/dt>/) do |m|
text = $1.tr("^A-Za-z0-9-", "")
anchor = "#{path}-#{text}"
+ # handle anchor collisions by appending -1
+ while ids.include?(anchor)
+ anchor += "-1"
+ end
+ ids.add(anchor)
"<dt class=\"hdlist1\" id=\"#{anchor}\"> <a class=\"anchor\" href=\"##{anchor}\"></a>#{$1} </dt>"
end
doc.plain = asciidoc.source