From cac363f69102f6f557697a3a7ee8ddbd2fef37d2 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Wed, 20 Sep 2023 15:43:12 +0200 Subject: [PATCH] Simplify --- lib/admonition_block_formatter.rb | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/lib/admonition_block_formatter.rb b/lib/admonition_block_formatter.rb index b42ef80..72c765e 100644 --- a/lib/admonition_block_formatter.rb +++ b/lib/admonition_block_formatter.rb @@ -1,29 +1,7 @@ class AdmonitionBlockFormatter - def self.format(code) - [:format_four, :format_three].each do |meth| - while code != (new_code = send(meth, code)) - code = new_code - end - end + def self.format(code) = code.gsub(BACKTICK_MATCH_REGEX, TILDE_REPLACE) - code - end - - def self.format_three(code) - matches = THREE_TILDE_REGEX.match(code) - return code unless matches - - matches['before'] + "~~~~" + matches['type'] + matches['admonition'] + "~~~~" + matches['after'] - end - - def self.format_four(code) - matches = FOUR_TILDE_REGEX.match(code) - return code unless matches - - matches['before'] + "~~~~" + matches['type'] + matches['admonition'] + "~~~~" + matches['after'] - end - - THREE_TILDE_REGEX = /(?[\s\S]*)(?`{3,})(?exercism\/[a-z]+)(?[\s\S]*?)(?\k)(?[\s\S]*)/.freeze - FOUR_TILDE_REGEX = /(?[\s\S]*)(?`{4,})(?exercism\/[a-z]+)(?[\s\S]*?)(?\k)(?[\s\S]*)/.freeze + BACKTICK_MATCH_REGEX = /(?`{3,})(?exercism\/[a-z]+)(?[\s\S]*?)(?\k)/.freeze + TILDE_REPLACE = '~~~~\k\k~~~~'.freeze end