2020-07-15 14:09:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Utils
|
|
|
|
module Markdown
|
|
|
|
PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze
|
2021-01-27 22:09:02 -05:00
|
|
|
PRODUCT_SUFFIX = /\s*\**\((core|starter|premium|ultimate|free|bronze|silver|gold)(\s+(only|self|sass))?\)\**/.freeze
|
2020-07-15 14:09:09 -04:00
|
|
|
|
|
|
|
def string_to_anchor(string)
|
|
|
|
string
|
|
|
|
.strip
|
|
|
|
.downcase
|
2020-09-07 08:08:27 -04:00
|
|
|
.gsub(PRODUCT_SUFFIX, '')
|
2020-07-15 14:09:09 -04: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
|