From 6aed7fda1ee53ce5aaa7800bcba83c9ae1dc1fda Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Mon, 3 Apr 2023 23:19:00 +0800 Subject: [PATCH] chat-block-processor: create the helper functions --- lib/asciidoctor/custom_extensions/chat_block_processor.rb | 8 ++++++++ 1 file changed, 8 insertions(+) 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