Permalink
Browse files

changed Markdown implementation to red carpet

  • Loading branch information...
1 parent bb2c546 commit e7317922dd57a10a3b4fb9bee9f290a286814f0a @rsim committed Mar 11, 2013
Showing with 61 additions and 4 deletions.
  1. +3 −1 Gemfile
  2. +6 −2 Gemfile.lock
  3. +4 −1 _config.yml
  4. +48 −0 _plugins/redcarpet2_markdown.rb
View
4 Gemfile
@@ -3,4 +3,6 @@ source 'http://rubygems.org'
gem 'jekyll'
gem 'gsl'
gem 'RedCloth'
-gem 'rdiscount'
+# gem 'rdiscount'
+gem 'redcarpet'
+gem 'albino'
View
8 Gemfile.lock
@@ -2,6 +2,8 @@ GEM
remote: http://rubygems.org/
specs:
RedCloth (4.2.9)
+ albino (1.3.3)
+ posix-spawn (>= 0.3.6)
classifier (1.3.3)
fast-stemmer (>= 1.0.0)
directory_watcher (1.4.0)
@@ -17,14 +19,16 @@ GEM
maruku (0.6.0)
syntax (>= 1.0.0)
narray (0.6.0.8)
- rdiscount (2.0.7.1)
+ posix-spawn (0.3.6)
+ redcarpet (2.2.2)
syntax (1.0.0)
PLATFORMS
ruby
DEPENDENCIES
RedCloth
+ albino
gsl
jekyll
- rdiscount
+ redcarpet
View
5 _config.yml
@@ -1,4 +1,7 @@
-markdown: rdiscount
+# markdown: rdiscount
+markdown: redcarpet2
+redcarpet:
+ extensions: ["no_intra_emphasis", "fenced_code_blocks", "autolink", "strikethrough", "superscript", "with_toc_data"]
pygments: true
permalink: /:year/:month/:day/:title/
exclude: deploy.rb Rakefile README.textile
View
48 _plugins/redcarpet2_markdown.rb
@@ -0,0 +1,48 @@
+require 'fileutils'
+require 'digest/md5'
+require 'redcarpet'
+require 'albino'
+
+PYGMENTS_CACHE_DIR = File.expand_path('../../_cache', __FILE__)
+FileUtils.mkdir_p(PYGMENTS_CACHE_DIR)
+
+class Redcarpet2Markdown < Redcarpet::Render::HTML
+ def block_code(code, lang)
+ lang = lang || "text"
+ path = File.join(PYGMENTS_CACHE_DIR, "#{lang}-#{Digest::MD5.hexdigest code}.html")
+ cache(path) do
+ colorized = Albino.colorize(code, lang.downcase)
+ add_code_tags(colorized, lang)
+ end
+ end
+
+ def add_code_tags(code, lang)
+ code.sub(/<pre>/, "<pre><code class=\"#{lang}\">").
+ sub(/<\/pre>/, "</code></pre>")
+ end
+
+ def cache(path)
+ if File.exist?(path)
+ File.read(path)
+ else
+ content = yield
+ File.open(path, 'w') {|f| f.print(content) }
+ content
+ end
+ end
+end
+
+class Jekyll::MarkdownConverter
+ def extensions
+ Hash[ *@config['redcarpet']['extensions'].map {|e| [e.to_sym, true] }.flatten ]
+ end
+
+ def markdown
+ @markdown ||= Redcarpet::Markdown.new(Redcarpet2Markdown.new(extensions), extensions)
+ end
+
+ def convert(content)
+ return super unless @config['markdown'] == 'redcarpet2'
+ markdown.render(content)
+ end
+end

0 comments on commit e731792

Please sign in to comment.