Skip to content

Commit

Permalink
For html, only wrap outermost layer in pre. A stab at resolving https…
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Haskin committed Mar 2, 2012
1 parent fea9567 commit b1b8dd1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
awesome_print (1.0.0)
awesome_print (1.0.2)

GEM
remote: http://rubygems.org/
Expand Down
3 changes: 2 additions & 1 deletion lib/awesome_print/core_ext/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module Kernel

def ai(options = {})
ap = AwesomePrint::Inspector.new(options)
ap.awesome self
awesome = ap.awesome self
options[:html] ? "<pre>#{awesome}</pre>" : awesome
end
alias :awesome_inspect :ai

Expand Down
2 changes: 1 addition & 1 deletion lib/awesome_print/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def format(object, type = nil)
else
awesome_self(object, type) # Catch all that falls back to object.inspect.
end
@options[:html] ? "<pre>#{awesome}</pre>" : awesome
#@options[:html] ? "<pre>#{awesome}</pre>" : awesome
end

# Hook this when adding custom formatters. Check out lib/awesome_print/ext
Expand Down
20 changes: 17 additions & 3 deletions spec/formats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,27 @@ def inspect
markup = [ 1, :two, "three" ]
markup.ai(:html => true).should == <<-EOS.strip
<pre>[
<kbd style="color:white">[0] </kbd><pre><kbd style="color:blue">1</kbd></pre>,
<kbd style="color:white">[1] </kbd><pre><kbd style="color:darkcyan">:two</kbd></pre>,
<kbd style="color:white">[2] </kbd><pre><kbd style="color:brown">&quot;three&quot;</kbd></pre>
<kbd style="color:white">[0] </kbd><kbd style="color:blue">1</kbd>,
<kbd style="color:white">[1] </kbd><kbd style="color:darkcyan">:two</kbd>,
<kbd style="color:white">[2] </kbd><kbd style="color:brown">&quot;three&quot;</kbd>
]</pre>
EOS
end

it "does not try to nest <pre> tag deeper than one level" do
markup = [ { "hello" => "world" }, { "goodbye" => "indents" } ]
markup.ai(:html => true).should == <<-EOS.strip
<pre>[
<kbd style="color:white">[0] </kbd>{
&quot;hello&quot;<kbd style="color:slategray"> =&gt; </kbd><kbd style="color:brown">&quot;world&quot;</kbd>
},
<kbd style="color:white">[1] </kbd>{
&quot;goodbye&quot;<kbd style="color:slategray"> =&gt; </kbd><kbd style="color:brown">&quot;indents&quot;</kbd>
}
]</pre>
EOS
end

it "encodes HTML entities (plain)" do
markup = ' &<hello>'
markup.ai(:html => true, :plain => true).should == '<pre>&quot; &amp;&lt;hello&gt;&quot;</pre>'
Expand Down

0 comments on commit b1b8dd1

Please sign in to comment.