Skip to content
Browse files

Add HTML unescaping to deal with the escaped output from Markdown

  • Loading branch information...
1 parent 52a4483 commit b3598e5477957e9cd1da06d91b0ece5aa29d7bbe @krohrbaugh committed Apr 13, 2012
Showing with 14 additions and 14 deletions.
  1. +3 −0 CHANGELOG
  2. +1 −1 README.markdown
  3. +1 −0 Rakefile
  4. +7 −10 lib/rack/pygmoku.rb
  5. +1 −1 lib/rack/pygmoku/version.rb
  6. +1 −2 spec/lib/rack/pygmoku_spec.rb
View
3 CHANGELOG
@@ -1,2 +1,5 @@
0.1.0
* Initial version; basic implementation
+
+0.1.1
+* Add HTML unescaping to deal with the escaped output from Markdown
View
2 README.markdown
@@ -10,7 +10,7 @@ In other words, it's ideal for use on Heroku.
First, of course, install the gem.
-Currently, `rack-pygmoku` only support Markdown-style code blocks, like
+Currently, `rack-pygmoku` only supports Markdown-style code blocks, like
so:
<pre data-lang='ruby'>
View
1 Rakefile
@@ -25,6 +25,7 @@ Jeweler::Tasks.new do |gem|
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
gem.add_runtime_dependency 'nokogiri', '~> 1.4'
gem.add_runtime_dependency 'pygments.rb', '~> 0'
+ gem.add_runtime_dependency 'rack', '~> 1.2'
gem.add_development_dependency 'rspec', '~> 2.5.0'
# Exclude files that are for development purposes
gem.files.exclude 'watchr.rb'
View
17 lib/rack/pygmoku.rb
@@ -5,9 +5,8 @@ module Rack
class Pygmoku
include Rack::Utils
- def initialize(app, opts={})
+ def initialize(app)
@app = app
- @opts = default_opts.merge(opts)
end
def call(env)
@@ -27,7 +26,7 @@ def call(env)
def highlight?(status, headers)
status == 200 &&
!headers['Transfer-Encoding'] &&
- headers['Content-Type'] =~ /html/
+ headers['Content-Type'] =~ /html/
end
def highlight(content)
@@ -40,9 +39,9 @@ def highlight(content)
nodes.each do |node|
parent_node = node.parent
lexer = get_lexer(parent_node)
+ content = unescape_html(node.content)
- highlighted = Pygments.highlight(
- node.content, {:lexer => lexer })
+ highlighted = Pygments.highlight(content, {:lexer => lexer })
parent_node.replace(highlighted)
parent_node.remove()
end
@@ -61,11 +60,9 @@ def get_lexer(node)
lexer
end
- def default_opts
- {
- :element => 'pre>code',
- :lexer_attr => 'data-lang'
- }
+ def unescape_html(html)
+ html.to_s.gsub(/&#x000A;/i, "\n").gsub("&lt;", '<').gsub(
+ "&gt;", '>').gsub("&amp;", '&')
end
end
end
View
2 lib/rack/pygmoku/version.rb
@@ -3,7 +3,7 @@ class Pygmoku
module Version
MAJOR = 0
MINOR = 1
- FIX = 0
+ FIX = 1
PRE = nil
STRING = [MAJOR, MINOR, FIX, PRE].compact.join('.')
View
3 spec/lib/rack/pygmoku_spec.rb
@@ -1,13 +1,12 @@
require 'spec_helper'
describe Rack::Pygmoku do
- let(:pygmoku) { Rack::Pygmoku.new(app, opts) }
+ let(:pygmoku) { Rack::Pygmoku.new(app) }
let(:app) do
rack_app = double('app').as_null_object
rack_app.stub(:call).and_return([status, headers, response])
rack_app
end
- let(:opts) { Hash.new }
let(:status) { 500 }
let(:headers) { { 'Content-Length' => 0, 'Content-Type' => content_type } }
let(:content_type) { 'text/plain' }

0 comments on commit b3598e5

Please sign in to comment.
Something went wrong with that request. Please try again.