Commit c2215a75 authored by Achilleas Pipinellis's avatar Achilleas Pipinellis

Merge branch 'remove-product-suffix-from-anchors' into 'master'

Remove product suffixes from anchors

See merge request gitlab-org/gitlab!39717
parents 2c2e5f76 6b765d0b
...@@ -45,6 +45,7 @@ docs lint: ...@@ -45,6 +45,7 @@ docs lint:
image: "registry.gitlab.com/gitlab-org/gitlab-docs/lint:vale-2.3.3-markdownlint-0.23.2" image: "registry.gitlab.com/gitlab-org/gitlab-docs/lint:vale-2.3.3-markdownlint-0.23.2"
stage: test stage: test
needs: [] needs: []
allow_failure: true
script: script:
- scripts/lint-doc.sh - scripts/lint-doc.sh
# Prepare docs for build # Prepare docs for build
......
...@@ -92,7 +92,8 @@ module HamlLint ...@@ -92,7 +92,8 @@ module HamlLint
File.open(path_to_file).any? do |line| File.open(path_to_file).any? do |line|
result = line.match(MARKDOWN_HEADER) result = line.match(MARKDOWN_HEADER)
string_to_anchor(result[:header]) == anchor if result # TODO:Do an exact match for anchors (Follow-up https://gitlab.com/gitlab-org/gitlab/-/merge_requests/39850)
anchor.start_with?(string_to_anchor(result[:header])) if result
end end
end end
end end
......
...@@ -4,11 +4,13 @@ module Gitlab ...@@ -4,11 +4,13 @@ module Gitlab
module Utils module Utils
module Markdown module Markdown
PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze
PRODUCT_SUFFIX = /\s*\((core|starter|premium|ultimate)(\s+only)?\)/.freeze
def string_to_anchor(string) def string_to_anchor(string)
string string
.strip .strip
.downcase .downcase
.gsub(PRODUCT_SUFFIX, '')
.gsub(PUNCTUATION_REGEXP, '') # remove punctuation .gsub(PUNCTUATION_REGEXP, '') # remove punctuation
.tr(' ', '-') # replace spaces with dash .tr(' ', '-') # replace spaces with dash
.squeeze('-') # replace multiple dashes with one .squeeze('-') # replace multiple dashes with one
......
...@@ -20,6 +20,13 @@ RSpec.describe HamlLint::Linter::DocumentationLinks do ...@@ -20,6 +20,13 @@ RSpec.describe HamlLint::Linter::DocumentationLinks do
it { is_expected.not_to report_lint } it { is_expected.not_to report_lint }
end end
# TODO: Remove me after https://gitlab.com/gitlab-org/gitlab/-/merge_requests/39715 is merged
context 'when link_to points to the existing file with partially matching anchor' do
let(:haml) { "= link_to 'Description', help_page_path('README.md', anchor: 'overview-premium'), target: '_blank'" }
it { is_expected.not_to report_lint }
end
context 'when link_to points to the existing file path without .md extension' do context 'when link_to points to the existing file path without .md extension' do
let(:haml) { "= link_to 'Description', help_page_path('README')" } let(:haml) { "= link_to 'Description', help_page_path('README')" }
......
...@@ -65,6 +65,11 @@ RSpec.describe Banzai::Filter::TableOfContentsFilter do ...@@ -65,6 +65,11 @@ RSpec.describe Banzai::Filter::TableOfContentsFilter do
expect(doc.css('h1 a').first.attr('href')).to eq '#title-with-spaces' expect(doc.css('h1 a').first.attr('href')).to eq '#title-with-spaces'
end 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 it 'appends a unique number to duplicates' do
doc = filter(header(1, 'One') + header(2, 'One')) doc = filter(header(1, 'One') + header(2, 'One'))
......
...@@ -52,6 +52,22 @@ RSpec.describe Gitlab::Utils::Markdown do ...@@ -52,6 +52,22 @@ RSpec.describe Gitlab::Utils::Markdown do
end end
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
context 'with only modifier' do
let(:string) { 'My Header (STARTER ONLY)' }
it 'ignores a product suffix' do
is_expected.to eq 'my-header'
end
end
end
context 'when string is empty' do context 'when string is empty' do
let(:string) { '' } 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