From 74cc258e89b6159d6c45dfde095d41468ee35da8 Mon Sep 17 00:00:00 2001 From: Laura Radville Date: Fri, 2 Aug 2024 16:33:39 -0400 Subject: [PATCH 1/3] freezes strings by default and leaves others unfrozen --- lib/org-ruby/html_output_buffer.rb | 8 +++++--- lib/org-ruby/markdown_output_buffer.rb | 2 +- lib/org-ruby/output_buffer.rb | 4 +++- lib/org-ruby/parser.rb | 8 +++++--- lib/org-ruby/textile_output_buffer.rb | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb index 180bd80..98050ee 100644 --- a/lib/org-ruby/html_output_buffer.rb +++ b/lib/org-ruby/html_output_buffer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Orgmode class HtmlOutputBuffer < OutputBuffer @@ -191,7 +193,7 @@ def flush! @output << inline_formatting(@buffer) end end - @buffer = "" + @buffer = +"" end def add_line_attributes headline @@ -214,7 +216,7 @@ def output_footnotes! @output << "\n
\n

Footnotes:

\n
\n" @footnotes.each do |name, (defi, content)| - @buffer = defi + @buffer = +defi @output << "
#{name}" \ << "

" \ << inline_formatting(@buffer) \ @@ -424,7 +426,7 @@ def strip_code_block! # # => "Usage: foo "bar" <baz>" private def escapeHTML(string) - string.gsub(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__) + +(string.gsub(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__)) end end # class HtmlOutputBuffer end # module Orgmode diff --git a/lib/org-ruby/markdown_output_buffer.rb b/lib/org-ruby/markdown_output_buffer.rb index b29d91f..7e8e0bd 100644 --- a/lib/org-ruby/markdown_output_buffer.rb +++ b/lib/org-ruby/markdown_output_buffer.rb @@ -105,7 +105,7 @@ def flush! end @output << inline_formatting(@buffer) << "\n" end - @buffer = "" + @buffer = +"" end def add_line_attributes headline diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb index 90a0aae..86238e7 100644 --- a/lib/org-ruby/output_buffer.rb +++ b/lib/org-ruby/output_buffer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'logger' module Orgmode @@ -20,7 +22,7 @@ def initialize(output) # This is the accumulation buffer. It's a holding pen so # consecutive lines of the right type can get stuck together # without intervening newlines. - @buffer = "" + @buffer = +"" # This stack is used to do proper outline numbering of # headlines. diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb index a57fd9e..6493b69 100644 --- a/lib/org-ruby/parser.rb +++ b/lib/org-ruby/parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rubypants' module Orgmode @@ -301,7 +303,7 @@ def self.load(fname, opts = {}) # Saves the loaded orgmode file as a textile file. def to_textile - output = "" + output = +"" output_buffer = TextileOutputBuffer.new(output) translate(@header_lines, output_buffer) @@ -317,7 +319,7 @@ def to_markdown export_options = { :markup_file => @parser_options[:markup_file] } - output = "" + output = +"" output_buffer = MarkdownOutputBuffer.new(output, export_options) translate(@header_lines, output_buffer) @@ -349,7 +351,7 @@ def to_html :markup_file => @parser_options[:markup_file] } export_options[:skip_tables] = true if not export_tables? - output = "" + output = +"" output_buffer = HtmlOutputBuffer.new(output, export_options) if @in_buffer_settings["TITLE"] diff --git a/lib/org-ruby/textile_output_buffer.rb b/lib/org-ruby/textile_output_buffer.rb index 58d3f22..42fa76f 100644 --- a/lib/org-ruby/textile_output_buffer.rb +++ b/lib/org-ruby/textile_output_buffer.rb @@ -144,7 +144,7 @@ def flush! end @output << inline_formatting(@buffer) << "\n" end - @buffer = "" + @buffer = +"" end def add_line_attributes headline From 880aeba3eaf37be69d5c0c3989a6af70f7209b6a Mon Sep 17 00:00:00 2001 From: Laura Radville Date: Wed, 14 Aug 2024 11:09:14 -0400 Subject: [PATCH 2/3] marks spec strings as mutable --- spec/regexp_helper_spec.rb | 10 +++++----- spec/textile_output_buffer_spec.rb | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/regexp_helper_spec.rb b/spec/regexp_helper_spec.rb index 694405a..0fdf863 100644 --- a/spec/regexp_helper_spec.rb +++ b/spec/regexp_helper_spec.rb @@ -40,7 +40,7 @@ "/" => "i", "~" => "code" } - n = e.rewrite_emphasis("This string contains *bold*, /italic/, and ~verbatim~ text.") do |border, str| + n = e.rewrite_emphasis(+"This string contains *bold*, /italic/, and ~verbatim~ text.") do |border, str| "<#{map[border]}>#{str}" end n = e.restore_code_snippets n @@ -50,15 +50,15 @@ it "should allow link rewriting" do e = Orgmode::RegexpHelper.new - str = e.rewrite_links("[[http://www.bing.com]]") do |link,text| + str = e.rewrite_links(+"[[http://www.bing.com]]") do |link,text| text ||= link "\"#{text}\":#{link}" end expect(str).to eql("\"http://www.bing.com\":http://www.bing.com") - str = e.rewrite_links("") do |link| + str = e.rewrite_links(+"") do |link| "\"#{link}\":#{link}" end - expect(str).to eql("\"http://www.google.com\":http://www.google.com") + expect(str).to eql(+"\"http://www.google.com\":http://www.google.com") end it "should allow quotes within code markup" do @@ -66,7 +66,7 @@ map = { "~" => "code" } - n = e.rewrite_emphasis('This string contains a quote using code markup: ~"~') do |border, str| + n = e.rewrite_emphasis(+'This string contains a quote using code markup: ~"~') do |border, str| "<#{map[border]}>#{str}" end n = e.restore_code_snippets n diff --git a/spec/textile_output_buffer_spec.rb b/spec/textile_output_buffer_spec.rb index fe21ee6..bee8182 100644 --- a/spec/textile_output_buffer_spec.rb +++ b/spec/textile_output_buffer_spec.rb @@ -2,20 +2,20 @@ describe Orgmode::TextileOutputBuffer do it "should substitute / with _" do - expect(Orgmode::TextileOutputBuffer.new("").inline_formatting("/italic/")).to eql("_italic_") + expect(Orgmode::TextileOutputBuffer.new("").inline_formatting(+"/italic/")).to eql("_italic_") end it "should convert simple links" do - expect(Orgmode::TextileOutputBuffer.new("").inline_formatting("[[http://www.google.com]]")).to \ + expect(Orgmode::TextileOutputBuffer.new("").inline_formatting(+"[[http://www.google.com]]")).to \ eql("\"http://www.google.com\":http://www.google.com") end it "should convert links with text" do - expect(Orgmode::TextileOutputBuffer.new("").inline_formatting("[[http://www.google.com][Google]]")).to \ + expect(Orgmode::TextileOutputBuffer.new("").inline_formatting(+"[[http://www.google.com][Google]]")).to \ eql("\"Google\":http://www.google.com") end it "should convert spaces in urls" do - expect(Orgmode::TextileOutputBuffer.new("").inline_formatting("[[my url]]")).to eql("\"my url\":my%20url") + expect(Orgmode::TextileOutputBuffer.new("").inline_formatting(+"[[my url]]")).to eql("\"my url\":my%20url") end end From 61083a9934b77a577808a338cc389e722dda86e5 Mon Sep 17 00:00:00 2001 From: Laura Radville Date: Wed, 14 Aug 2024 11:14:42 -0400 Subject: [PATCH 3/3] unfreezes a string --- spec/textile_output_buffer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/textile_output_buffer_spec.rb b/spec/textile_output_buffer_spec.rb index bee8182..7e32fb1 100644 --- a/spec/textile_output_buffer_spec.rb +++ b/spec/textile_output_buffer_spec.rb @@ -16,6 +16,6 @@ end it "should convert spaces in urls" do - expect(Orgmode::TextileOutputBuffer.new("").inline_formatting(+"[[my url]]")).to eql("\"my url\":my%20url") + expect(Orgmode::TextileOutputBuffer.new("").inline_fgit ormatting(+"[[my url]]")).to eql("\"my url\":my%20url") end end