diff options
author | Pedro Rijo <pedrorijo91@gmail.com> | 2022-09-17 23:10:40 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-17 23:10:40 +0300 |
commit | 26916dfb50802a32b1f57bd902fa732c8fd16863 (patch) | |
tree | 2368ffe7111593ebdd8d2fab04f40ae3a8e581f9 | |
parent | d40a3f990d26acbcbb6c7b5c101fde43ee930208 (diff) | |
parent | 81d803ed8f0c36d7d6abf1845bb43d072603206f (diff) |
Merge pull request #1730 from samccone/fix-anchors
Handle colliding anchors in documentation pages
-rw-r--r-- | lib/tasks/index.rake | 14 |
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 |