diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2017-12-08 12:50:22 +0300 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2017-12-08 16:13:18 +0300 |
commit | 3e83d9f73a2dbec010026dbcd24effe89d4dc16f (patch) | |
tree | 10bee33e10b0b469c018a8573e4d3162c485e3be /spec/lib/banzai/filter | |
parent | 29e39e55c3d4b5c6c34c6faec84b0dcd5a3efffa (diff) |
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 'spec/lib/banzai/filter')
-rw-r--r-- | spec/lib/banzai/filter/table_of_contents_filter_spec.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb index 85eddde732e..0cfef4ff5bf 100644 --- a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb +++ b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb @@ -65,6 +65,13 @@ describe Banzai::Filter::TableOfContentsFilter do expect(doc.css('h2 a').first.attr('href')).to eq '#one-1' end + it 'prepends a prefix to digits-only ids' do + doc = filter(header(1, "123") + header(2, "1.0")) + + expect(doc.css('h1 a').first.attr('href')).to eq '#anchor-123' + expect(doc.css('h2 a').first.attr('href')).to eq '#anchor-10' + end + it 'supports Unicode' do doc = filter(header(1, '한글')) expect(doc.css('h1 a').first.attr('id')).to eq 'user-content-한글' |