Skip to content

Commit

Permalink
Do not escape snippets twice
Browse files Browse the repository at this point in the history
Markup helpers aleardy done escaping. This is actually partial revert of
414e534

Closes lsegal#445 referencing lsegal#467
  • Loading branch information
avsej authored and lsegal committed Jan 19, 2012
1 parent 115fc6b commit aeadc03
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/yard/templates/helpers/html_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def htmlify(text, markup = options[:markup])
html = html.gsub(/<pre\s*(?:lang="(.+?)")?>(?:\s*<code\s*(?:class="(.+?)")?\s*>)?(.+?)(?:<\/code>\s*)?<\/pre>/m) do
language = $1 || $2
string = $3
string = html_syntax_highlight(h(string), language) unless options[:no_highlight]

string = html_syntax_highlight(CGI.unescapeHTML(string), language) unless options[:no_highlight]
classes = ['code', language].compact.join(' ')
%Q{<pre class="#{classes}"><code>#{string}</code></pre>}
end unless [:text, :none, :pre].include?(markup)
Expand Down
5 changes: 5 additions & 0 deletions spec/templates/helpers/html_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,11 @@ def x; end
htmlify('def x; end', :ruby).should == '<pre class="code ruby">x</pre>'
end

it "shouldn't escape code snippets twice" do
htmlify('<pre lang="foo"><code>{"foo" => 1}</code></pre>', :html).should ==
'<pre class="code foo"><code>{&quot;foo&quot; =&gt; 1}</code></pre>'
end

it "should highlight source when matching a pre lang= tag" do
htmlify('<pre lang="foo"><code>x = 1</code></pre>', :html).should ==
'<pre class="code foo"><code>x = 1</code></pre>'
Expand Down

0 comments on commit aeadc03

Please sign in to comment.