debian-mirror-gitlab/lib/gitlab/utils/markdown.rb

22 lines
629 B
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module Gitlab
module Utils
module Markdown
PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze
2020-11-24 15:15:51 +05:30
PRODUCT_SUFFIX = /\s*\**\((core|starter|premium|ultimate)(\s+only)?\)\**/.freeze
2020-07-28 23:09:34 +05:30
def string_to_anchor(string)
string
.strip
.downcase
2020-11-24 15:15:51 +05:30
.gsub(PRODUCT_SUFFIX, '')
2020-07-28 23:09:34 +05:30
.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