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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2016-11-21 21:02:19 +0300
committerMike Greiling <mike@pixelcog.com>2016-12-01 00:28:10 +0300
commitff2026f40ec0bc162dc4281b067ed4716b2ad248 (patch)
tree9354091f406a62c692b699a9c5742bef34a341ce /lib/banzai
parentffd28232610b87b3c738357655b95feedb3479d0 (diff)
add transparent namespace to all user-generated anchors in GitLab flavored markdown
Diffstat (limited to 'lib/banzai')
-rw-r--r--lib/banzai/filter/table_of_contents_filter.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/banzai/filter/table_of_contents_filter.rb b/lib/banzai/filter/table_of_contents_filter.rb
index a4eda6fdf76..80669953723 100644
--- a/lib/banzai/filter/table_of_contents_filter.rb
+++ b/lib/banzai/filter/table_of_contents_filter.rb
@@ -35,9 +35,11 @@ module Banzai
headers[id] += 1
if header_content = node.children.first
+ # namespace detection will be automatically handled via javascript (see issue #22781)
+ namespace = "user-content_"
href = "#{id}#{uniq}"
push_toc(href, text)
- header_content.add_previous_sibling(anchor_tag(href))
+ header_content.add_previous_sibling(anchor_tag("#{namespace}#{href}", href))
end
end
@@ -48,8 +50,8 @@ module Banzai
private
- def anchor_tag(href)
- %Q{<a id="#{href}" class="anchor" href="##{href}" aria-hidden="true"></a>}
+ def anchor_tag(id, href)
+ %Q{<a id="#{id}" class="anchor" href="##{href}" aria-hidden="true"></a>}
end
def push_toc(href, text)