2020-07-15 18:09:09 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Utils
|
|
|
|
module Markdown
|
|
|
|
PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze
|
2020-09-12 00:08:44 +00:00
|
|
|
PRODUCT_SUFFIX = /\s*\**\((core|starter|premium|ultimate)(\s+only)?\)\**/.freeze
|
2020-07-15 18:09:09 +00:00
|
|
|
|
|
|
|
def string_to_anchor(string)
|
|
|
|
string
|
|
|
|
.strip
|
|
|
|
.downcase
|
2020-09-07 12:08:27 +00:00
|
|
|
.gsub(PRODUCT_SUFFIX, '')
|
2020-07-15 18:09:09 +00:00
|
|
|
.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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|