Commit 51f6e866 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Remove product suffix from anchors

parent 2ac47a71
......@@ -4,9 +4,11 @@ module Gitlab
module Utils
module Markdown
PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze
PRODUCT_SUFFIX = /\((CORE|STARTER|PREMIUM|ULTIMATE)(\s+ONLY)?\)/.freeze
def string_to_anchor(string)
string
.gsub(PRODUCT_SUFFIX, '')
.strip
.downcase
.gsub(PUNCTUATION_REGEXP, '') # remove punctuation
......
......@@ -65,6 +65,11 @@ RSpec.describe Banzai::Filter::TableOfContentsFilter do
expect(doc.css('h1 a').first.attr('href')).to eq '#title-with-spaces'
end
it 'removes a product suffix' do
doc = filter(header(1, "Title with spaces (ULTIMATE)"))
expect(doc.css('h1 a').first.attr('href')).to eq '#title-with-spaces'
end
it 'appends a unique number to duplicates' do
doc = filter(header(1, 'One') + header(2, 'One'))
......
......@@ -52,6 +52,14 @@ RSpec.describe Gitlab::Utils::Markdown do
end
end
context 'when string has a product suffix' do
let(:string) { 'My Header (ULTIMATE)' }
it 'ignores a product suffix' do
is_expected.to eq 'my-header'
end
end
context 'when string is empty' do
let(:string) { '' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment