diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2017-12-08 10:50:22 +0100 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2017-12-08 14:13:18 +0100 |
commit | 3e83d9f73a2dbec010026dbcd24effe89d4dc16f (patch) | |
tree | 10bee33e10b0b469c018a8573e4d3162c485e3be /lib/banzai | |
parent | 29e39e55c3d4b5c6c34c6faec84b0dcd5a3efffa (diff) | |
download | gitlab-ce-3e83d9f73a2dbec010026dbcd24effe89d4dc16f.tar.gz |
Use prefix for TableOfContents filter hrefs
TableOfContents filter generates hrefs for each header in markdown,
if the header text consists from digits and redacted symbols only,
e.g. "123" or "1.0 then the auto-generated href has the same format
as issue references.
If the generated id contains only digits, then 'anchor-' prefix is
prepended to the id.
Closes #38473
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/filter/table_of_contents_filter.rb | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/banzai/filter/table_of_contents_filter.rb b/lib/banzai/filter/table_of_contents_filter.rb index 47151626208..97244159985 100644 --- a/lib/banzai/filter/table_of_contents_filter.rb +++ b/lib/banzai/filter/table_of_contents_filter.rb @@ -32,6 +32,7 @@ module Banzai .gsub(PUNCTUATION_REGEXP, '') # remove punctuation .tr(' ', '-') # replace spaces with dash .squeeze('-') # replace multiple dashes with one + .gsub(/\A(\d+)\z/, 'anchor-\1') # digits-only hrefs conflict with issue refs uniq = headers[id] > 0 ? "-#{headers[id]}" : '' headers[id] += 1 |