diff --git a/lib/asciidoctor/chat-block-processor/extension.rb b/lib/asciidoctor/chat-block-processor/extension.rb index ea5d930..52ec823 100644 --- a/lib/asciidoctor/chat-block-processor/extension.rb +++ b/lib/asciidoctor/chat-block-processor/extension.rb @@ -24,7 +24,7 @@ class ChatBlock < Asciidoctor::Extensions::BlockProcessor attrs['avatarsdir'] ||= File.expand_path('./avatars', attrs['iconsdir']) - avatar_sticker = "#{attrs['avatar'].to_snake}/#{attrs['state'].to_snake}.#{attrs['avatarstype']}" + avatar_sticker = "#{attrs['avatar'].to_kebab}/#{attrs['state'].to_kebab}.#{attrs['avatarstype']}" avatar_img_attrs = { 'target' => parent.image_uri(avatar_sticker, 'avatarsdir'), 'alt' => attrs['name'] diff --git a/lib/asciidoctor/helpers.rb b/lib/asciidoctor/helpers.rb index e2e7351..2158b38 100644 --- a/lib/asciidoctor/helpers.rb +++ b/lib/asciidoctor/helpers.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true -# Code copied from https://gist.github.com/komasaru/b3f22d5bcb8555deea1707b84d294045. class String - def to_snake - self.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') - .gsub(/([a-z\d])([A-Z])/, '\1_\2') + def to_kebab + self.gsub(/\s+/, '-') # Replace all spaces with dashes. + .gsub(/[^a-zA-Z0-9-]/, '') # Remove all non-alphanumerical (and dashes) characters. + .gsub(/-+/, '-') # Reduce all dashes into only one. + .gsub(/^-|-+$/, '') # Remove all leading and trailing dashes. .downcase end end