diff options
Diffstat (limited to 'lib/gitlab/utils/markdown.rb')
-rw-r--r-- | lib/gitlab/utils/markdown.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/gitlab/utils/markdown.rb b/lib/gitlab/utils/markdown.rb new file mode 100644 index 00000000000..82c4a0e3b23 --- /dev/null +++ b/lib/gitlab/utils/markdown.rb @@ -0,0 +1,19 @@ +# 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 |