Fixing Slideshow (S9) and Syntax Highlighting within Markdown

In another attempt to fill a blog entry title with as many buzzwords as I can, this diff can be applied to the code in your Slide Show library in order to take the suggestion of a previous developer and use CGI to unescape the HTML that comes back from syntax highlighting code, as opposed to manually trying to hit every element that might have been escaped.

Index: slideshow.rb
===================================================================
--- slideshow.rb	(revision 42)
+++ slideshow.rb	(working copy)
@@ -6,6 +6,7 @@
 require 'fileutils'
 require 'ftools'
 require 'hpricot'
+require 'cgi'
 require 'uv'
 
 
@@ -388,10 +389,7 @@
           if Uv.syntaxes.include?(lang)
             code = e.inner_html.sub(/^\s*#!\w+/, '').strip
 
-            code.gsub!( "&lt;", "<" )
-            code.gsub!( "&gt;", ">" )
-            code.gsub!( "&amp;", "&" )
-            # todo: missing any other entities? use CGI::unescapeHTML?
+            code = CGI::unescapeHTML(code)
             logger.debug "code=>#{code}<"
 
             code_highlighted = Uv.parse( code, "xhtml", lang, opts.code_line_numbers?, opts.code_theme )

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*