diff --git a/CHANGELOG.md b/CHANGELOG.md index 28d5078..3d8d1f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +### 0.6.2 / 2015-01-19 + +[full changelog](https://github.com/jedcn/reveal-ck/compare/v0.6.1...v0.6.2) + +#### Bug Fix: Escape HTML characters in Markdown code snippets + +This is a fix for Issue #32. + +reveal-ck now escapes HTML characters in markdown code snippets. + +Thanks to [@skirino][skirino] for both reporting the issue and fixing it! + +[skirino]: https://github.com/skirino + ### 0.6.1 / 2015-01-09 [full changelog](https://github.com/jedcn/reveal-ck/compare/v0.6.0...v0.6.1) diff --git a/features/generate-with-markdown.feature b/features/generate-with-markdown.feature index 0de43e2..5d0df37 100644 --- a/features/generate-with-markdown.feature +++ b/features/generate-with-markdown.feature @@ -363,3 +363,25 @@ Feature: Slides with markdown | //section[4]/section[2]/h1[text()="Column 2, Slide 2"] | Column 2, Slide 2 | | //section[4]/section[3]/h1[text()="Column 2, Slide 3"] | Column 2, Slide 3 | | //section[5]/h1[text()="Last"] | Last Slide | + + Scenario: Creating a slide with HTML special characters + Given a file named "slides.md" with: + """ + ``` + user=> (atom 10) + # + ``` + """ + When I run `reveal-ck generate` + Then the exit status should be 0 + And the file "slides/index.html" should have html matching the xpath: + | //section/pre/code[contains(., 'user=>')] | first line of escaped code | + | //section/pre/code[contains(., "#")] | second line of escaped code | + And the file "slides/index.html" should contain: + """ + user=> (atom 10) + """ + And the file "slides/index.html" should contain: + """ + #<Atom@6cbda790: 10> + """ diff --git a/lib/reveal-ck/markdown/slide_markdown.rb b/lib/reveal-ck/markdown/slide_markdown.rb index 46789dc..3af70a0 100644 --- a/lib/reveal-ck/markdown/slide_markdown.rb +++ b/lib/reveal-ck/markdown/slide_markdown.rb @@ -1,3 +1,4 @@ +require 'cgi' require 'redcarpet' module RevealCK @@ -13,12 +14,13 @@ def postprocess(doc) end def block_code(code, language) + escaped = CGI.escape_html(code) if language.nil? - "
#{code}
" + "
#{escaped}
" elsif language == 'notes' || language == 'note' - "" + "" else - "
#{code}
" + "
#{escaped}
" end end end diff --git a/lib/reveal-ck/version.rb b/lib/reveal-ck/version.rb index 73ca51a..e50a6e4 100644 --- a/lib/reveal-ck/version.rb +++ b/lib/reveal-ck/version.rb @@ -1,4 +1,4 @@ # RevealCK::VERSION is the current version of reveal-ck module RevealCK - VERSION = '0.6.1' + VERSION = '0.6.2' end diff --git a/reveal-ck.gemspec b/reveal-ck.gemspec index e2211b1..da06025 100644 --- a/reveal-ck.gemspec +++ b/reveal-ck.gemspec @@ -55,7 +55,7 @@ Gem::Specification.new do |s| s.executables = ['reveal-ck'] s.require_paths = ['lib'] - s.date = '2014-11-01' + s.date = '2015-01-19' s.extra_rdoc_files = [ 'LICENSE', 'README.md' diff --git a/spec/lib/reveal-ck/markdown/slide_markdown_template_spec.rb b/spec/lib/reveal-ck/markdown/slide_markdown_template_spec.rb index 80d1bec..3183f28 100644 --- a/spec/lib/reveal-ck/markdown/slide_markdown_template_spec.rb +++ b/spec/lib/reveal-ck/markdown/slide_markdown_template_spec.rb @@ -49,6 +49,17 @@ def adder(a, b); a + b; end expect(output).to include 'a + b' end + it 'converts special characters in ``` block to entity references' do + output = render_markdown <<-eos +``` +

"&"

+``` +eos + expect(output).to include '
'
+        expect(output).to include '
' + expect(output).to include '<p>"&"</p>' + end + it 'wraps ```ruby code in a
 and ' do
         output = render_markdown <<-eos
 ```ruby