Add method Repubmark.validate_slug!

This commit is contained in:
Alex Kotov 2024-09-28 02:18:28 +04:00
parent 4b5b7b79f5
commit e822bf6ce5
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -66,6 +66,8 @@ require_relative 'repubmark/elems/footnote'
module Repubmark
FORMATS = %i[gemtext html summary_plain word_count].freeze
SLUG_RE = /\A\w+(-\w+)*\z/
UNICODE_SUPS = {
'0' => '⁰',
'1' => '¹',
@ -102,6 +104,13 @@ module Repubmark
')' => '₎',
}.freeze
def self.validate_slug!(slug)
slug = String(slug).freeze
raise 'Invalid slug' unless SLUG_RE.match? slug
slug
end
def self.unicode_sup(val)
String(val).each_char.map { |chr| UNICODE_SUPS.fetch chr }.join.freeze
end