From 14d53d5f914fd926b49e6492fd7bd95e62ef541a Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Tue, 29 Oct 2024 19:35:18 +1100 Subject: [PATCH] Support frozen string literals (#105) This is to avoid deprecation warnings with the forthcoming change in Ruby 3.4 where modifying a string literal will cause a deprecation warning by default. https://github.com/ruby/ruby/commit/12be40ae6be78ac41e8e3f3c313cc6f63e7fa6c4 Co-authored-by: Johannes Opper --- lib/reverse_markdown/converters/base.rb | 2 +- lib/reverse_markdown/converters/blockquote.rb | 2 +- lib/reverse_markdown/converters/div.rb | 2 +- lib/reverse_markdown/converters/figcaption.rb | 2 +- lib/reverse_markdown/converters/ol.rb | 2 +- lib/reverse_markdown/converters/p.rb | 2 +- lib/reverse_markdown/converters/pre.rb | 4 ++-- lib/reverse_markdown/converters/table.rb | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/reverse_markdown/converters/base.rb b/lib/reverse_markdown/converters/base.rb index 7ab25ee..cfdf7c9 100644 --- a/lib/reverse_markdown/converters/base.rb +++ b/lib/reverse_markdown/converters/base.rb @@ -2,7 +2,7 @@ module ReverseMarkdown module Converters class Base def treat_children(node, state) - node.children.inject('') do |memo, child| + node.children.inject(+'') do |memo, child| memo << treat(child, state) end end diff --git a/lib/reverse_markdown/converters/blockquote.rb b/lib/reverse_markdown/converters/blockquote.rb index e4b2a97..68022a9 100644 --- a/lib/reverse_markdown/converters/blockquote.rb +++ b/lib/reverse_markdown/converters/blockquote.rb @@ -4,7 +4,7 @@ class Blockquote < Base def convert(node, state = {}) content = treat_children(node, state).strip content = ReverseMarkdown.cleaner.remove_newlines(content) - "\n\n> " << content.lines.to_a.join('> ') << "\n\n" + +"\n\n> " << content.lines.to_a.join('> ') << "\n\n" end end diff --git a/lib/reverse_markdown/converters/div.rb b/lib/reverse_markdown/converters/div.rb index ad26303..8d49344 100644 --- a/lib/reverse_markdown/converters/div.rb +++ b/lib/reverse_markdown/converters/div.rb @@ -2,7 +2,7 @@ module ReverseMarkdown module Converters class Div < Base def convert(node, state = {}) - "\n" << treat_children(node, state) << "\n" + +"\n" << treat_children(node, state) << "\n" end end diff --git a/lib/reverse_markdown/converters/figcaption.rb b/lib/reverse_markdown/converters/figcaption.rb index 30ec3f1..c8ebc86 100644 --- a/lib/reverse_markdown/converters/figcaption.rb +++ b/lib/reverse_markdown/converters/figcaption.rb @@ -5,7 +5,7 @@ def convert(node, state = {}) if node.text.strip.empty? "" else - "\n" << "_#{node.text.strip}_" << "\n" + +"\n" << "_#{node.text.strip}_" << "\n" end end end diff --git a/lib/reverse_markdown/converters/ol.rb b/lib/reverse_markdown/converters/ol.rb index 2fa3a02..b305b61 100644 --- a/lib/reverse_markdown/converters/ol.rb +++ b/lib/reverse_markdown/converters/ol.rb @@ -3,7 +3,7 @@ module Converters class Ol < Base def convert(node, state = {}) ol_count = state.fetch(:ol_count, 0) + 1 - "\n" << treat_children(node, state.merge(ol_count: ol_count)) << "\n" + +"\n" << treat_children(node, state.merge(ol_count: ol_count)) << "\n" end end diff --git a/lib/reverse_markdown/converters/p.rb b/lib/reverse_markdown/converters/p.rb index 67cc2c8..7144608 100644 --- a/lib/reverse_markdown/converters/p.rb +++ b/lib/reverse_markdown/converters/p.rb @@ -2,7 +2,7 @@ module ReverseMarkdown module Converters class P < Base def convert(node, state = {}) - "\n\n" << treat_children(node, state).strip << "\n\n" + +"\n\n" << treat_children(node, state).strip << "\n\n" end end diff --git a/lib/reverse_markdown/converters/pre.rb b/lib/reverse_markdown/converters/pre.rb index 2fec5d2..2b31a7b 100644 --- a/lib/reverse_markdown/converters/pre.rb +++ b/lib/reverse_markdown/converters/pre.rb @@ -4,9 +4,9 @@ class Pre < Base def convert(node, state = {}) content = treat_children(node, state) if ReverseMarkdown.config.github_flavored - "\n```#{language(node)}\n" << content.strip << "\n```\n" + +"\n```#{language(node)}\n" << content.strip << "\n```\n" else - "\n\n " << content.lines.to_a.join(" ") << "\n\n" + +"\n\n " << content.lines.to_a.join(" ") << "\n\n" end end diff --git a/lib/reverse_markdown/converters/table.rb b/lib/reverse_markdown/converters/table.rb index 5877c73..9f20939 100644 --- a/lib/reverse_markdown/converters/table.rb +++ b/lib/reverse_markdown/converters/table.rb @@ -2,7 +2,7 @@ module ReverseMarkdown module Converters class Table < Base def convert(node, state = {}) - "\n\n" << treat_children(node, state) << "\n" + +"\n\n" << treat_children(node, state) << "\n" end end