diff --git a/lib/asciidoctor/custom_extensions/chat_block_processor.rb b/lib/asciidoctor/custom_extensions/chat_block_processor.rb index e12c62a..5957e2d 100644 --- a/lib/asciidoctor/custom_extensions/chat_block_processor.rb +++ b/lib/asciidoctor/custom_extensions/chat_block_processor.rb @@ -1,5 +1,13 @@ # frozen_string_literal: true +def to_kebab_case string + string.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 + class ChatBlock < Asciidoctor::Extensions::BlockProcessor use_dsl