Permalink
Browse files

Fix immutable string errors

  • Loading branch information...
mvz committed Aug 26, 2017
1 parent 7a16c10 commit f2e1dfadba7a58dd9a078489497c0bd16413d0aa
Showing with 33 additions and 25 deletions.
  1. +3 −4 lib/redcloth/formatters/base.rb
  2. +2 −2 lib/redcloth/formatters/latex.rb
  3. +15 −15 spec/custom_tags_spec.rb
  4. +13 −4 spec/parser_spec.rb
@@ -28,7 +28,6 @@ def pba(opts)
opts.delete(:class) if filter_classes
opts.delete(:id) if filter_ids

atts = ''
opts[:"text-align"] = opts.delete(:align)
opts[:style] += ';' if opts[:style] && (opts[:style][-1..-1] != ';')
[:float, :"text-align", :"vertical-align"].each do |a|
@@ -37,10 +36,10 @@ def pba(opts)
[:"padding-right", :"padding-left"].each do |a|
opts[:style] = "#{a}:#{opts[a]}em;#{opts[:style]}" if opts[a]
end
[:style, :class, :lang, :id, :colspan, :rowspan, :title, :start, :align].each do |a|
atts << " #{a}=\"#{ html_esc(opts[a].to_s, :html_escape_attributes) }\"" if opts[a]
atts = [:style, :class, :lang, :id, :colspan, :rowspan, :title, :start, :align].map do |a|
" #{a}=\"#{ html_esc(opts[a].to_s, :html_escape_attributes) }\"" if opts[a]
end
atts
atts.compact.join
end

def method_missing(method, opts)
@@ -165,15 +165,15 @@ def table_open(opts)

# FIXME: need caption and label elements similar to image -> figure
def table_close(opts)
output = "\\begin{table}\n"
output = ["\\begin{table}\n"]
output << " \\centering\n"
output << " \\begin{tabular}{ #{"l " * @table[0].size }}\n"
@table.each do |row|
output << " #{row.join(" & ")} \\\\\n"
end
output << " \\end{tabular}\n"
output << "\\end{table}\n"
output
output.join
end

# code blocks
@@ -5,30 +5,30 @@ def fig( opts )
label, img = opts[:text].split('|').map! {|str| str.strip}

html = %Q{<div class="img" id="figure-#{label.tr('.', '-')}">\n}
html << %Q{ <a class="fig" href="/images/#{img}">\n}
html << %Q{ <img src="/images/thumbs/#{img}" alt="Figure #{label}" />\n}
html << %Q{ </a>\n}
html << %Q{ <p>Figure #{label}</p>\n}
html << %Q{<div>\n}
html += %Q{ <a class="fig" href="/images/#{img}">\n}
html += %Q{ <img src="/images/thumbs/#{img}" alt="Figure #{label}" />\n}
html += %Q{ </a>\n}
html += %Q{ <p>Figure #{label}</p>\n}
html += %Q{<div>\n}
end
end

describe "custom tags" do
it "should recognize the custom tag" do
input = %Q{The first line of text.\n\n}
input << %Q{fig. 1.1 | img.jpg\n\n}
input << %Q{The last line of text.\n}
input += %Q{fig. 1.1 | img.jpg\n\n}
input += %Q{The last line of text.\n}
r = RedCloth.new input
r.extend FigureTag

html = %Q{<p>The first line of text.</p>\n}
html << %Q{<div class="img" id="figure-1-1">\n}
html << %Q{ <a class="fig" href="/images/img.jpg">\n}
html << %Q{ <img src="/images/thumbs/img.jpg" alt="Figure 1.1" />\n}
html << %Q{ </a>\n}
html << %Q{ <p>Figure 1.1</p>\n}
html << %Q{<div>\n}
html << %Q{<p>The last line of text.</p>}
html += %Q{<div class="img" id="figure-1-1">\n}
html += %Q{ <a class="fig" href="/images/img.jpg">\n}
html += %Q{ <img src="/images/thumbs/img.jpg" alt="Figure 1.1" />\n}
html += %Q{ </a>\n}
html += %Q{ <p>Figure 1.1</p>\n}
html += %Q{<div>\n}
html += %Q{<p>The last line of text.</p>}

r.to_html.should == html
end
@@ -47,4 +47,4 @@ def fig( opts )

r.to_html.should == html
end
end
end
@@ -85,17 +85,26 @@

if RUBY_VERSION > "1.9.0"
it "should preserve character encoding" do
input = "This is an ISO-8859-1 string"
input.force_encoding 'iso-8859-1'
if RUBY_VERSION > "2.3.0"
input = String.new("This is an ISO-8859-1 string", encoding: 'iso-8859-1')
else
input = "This is an ISO-8859-1 string"
input.force_encoding 'iso-8859-1'
end

output = RedCloth.new(input).to_html

output.should == "<p>This is an <span class=\"caps\">ISO</span>-8859-1 string</p>"
output.encoding.to_s.should == "ISO-8859-1"
end

it "should not raise ArgumentError: invalid byte sequence" do
s = "\xa3"
s.force_encoding 'iso-8859-1'
if RUBY_VERSION > "2.3.0"
s = String.new("\xa3", encoding: 'iso-8859-1')
else
s = "\xa3"
s.force_encoding 'iso-8859-1'
end
lambda { RedCloth.new(s).to_html }.should_not raise_error
end
end

0 comments on commit f2e1dfa

Please sign in to comment.