Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marks strings as mutable in preparation for Ruby freezing strings #106

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/org-ruby/html_output_buffer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Orgmode

class HtmlOutputBuffer < OutputBuffer
Expand Down Expand Up @@ -191,7 +193,7 @@ def flush!
@output << inline_formatting(@buffer)
end
end
@buffer = ""
@buffer = +""
end

def add_line_attributes headline
Expand All @@ -214,7 +216,7 @@ def output_footnotes!

@output << "\n<div id=\"footnotes\">\n<h2 class=\"footnotes\">Footnotes:</h2>\n<div id=\"text-footnotes\">\n"
@footnotes.each do |name, (defi, content)|
@buffer = defi
@buffer = +defi
@output << "<div class=\"footdef\"><sup><a id=\"fn.#{name}\" href=\"#fnr.#{name}\">#{name}</a></sup>" \
<< "<p class=\"footpara\">" \
<< inline_formatting(@buffer) \
Expand Down Expand Up @@ -424,7 +426,7 @@ def strip_code_block!
# # => "Usage: foo &quot;bar&quot; &lt;baz&gt;"
private
def escapeHTML(string)
string.gsub(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__)
+(string.gsub(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__))
end
end # class HtmlOutputBuffer
end # module Orgmode
2 changes: 1 addition & 1 deletion lib/org-ruby/markdown_output_buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def flush!
end
@output << inline_formatting(@buffer) << "\n"
end
@buffer = ""
@buffer = +""
end

def add_line_attributes headline
Expand Down
4 changes: 3 additions & 1 deletion lib/org-ruby/output_buffer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'logger'

module Orgmode
Expand All @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions lib/org-ruby/parser.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rubypants'

module Orgmode
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion lib/org-ruby/textile_output_buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def flush!
end
@output << inline_formatting(@buffer) << "\n"
end
@buffer = ""
@buffer = +""
end

def add_line_attributes headline
Expand Down
10 changes: 5 additions & 5 deletions spec/regexp_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}</#{map[border]}>"
end
n = e.restore_code_snippets n
Expand All @@ -50,23 +50,23 @@

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("<http://www.google.com>") do |link|
str = e.rewrite_links(+"<http://www.google.com>") 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
e = Orgmode::RegexpHelper.new
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}</#{map[border]}>"
end
n = e.restore_code_snippets n
Expand Down
8 changes: 4 additions & 4 deletions spec/textile_output_buffer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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_fgit ormatting(+"[[my url]]")).to eql("\"my url\":my%20url")
end
end