Add method Repubmark.validate_slug!
This commit is contained in:
parent
4b5b7b79f5
commit
e822bf6ce5
1 changed files with 9 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue