debian-mirror-gitlab/lib/gitlab/utils/markdown.rb
2020-08-09 17:44:08 +05:30

20 lines
506 B
Ruby

# frozen_string_literal: true
module Gitlab
module Utils
module Markdown
PUNCTUATION_REGEXP = /[^\p{Word}\- ]/u.freeze
def string_to_anchor(string)
string
.strip
.downcase
.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