Created
March 8, 2015 16:09
-
-
Save Alfred-Sun/5e1f44bfdd19832f50fe to your computer and use it in GitHub Desktop.
Used to debug issue one and issue two fo redcarpet under windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use Jekyll process function | |
module CommonMethods | |
def add_code_tags(code, lang) | |
code = code.to_s | |
code = code.sub(/<pre>/, "<pre><code class=\"language-#{lang}\" data-lang=\"#{lang}\">") | |
code = code.sub(/<\/pre>/,"</code></pre>") | |
end | |
end | |
module WithPygments | |
include CommonMethods | |
def block_code(code, lang) | |
require "pygments" | |
lang = lang && lang.split.first || "text" | |
add_code_tags( | |
Pygments.highlight(code, :lexer => lang, :options => { :encoding => 'utf-8' }), | |
lang | |
) | |
end | |
end | |
require 'redcarpet' | |
@redcarpet_extensions = {} | |
@renderer = Class.new(Redcarpet::Render::HTML) do include WithPygments end | |
@redcarpet_extensions[:fenced_code_blocks] = !@redcarpet_extensions[:no_fenced_code_blocks] | |
@renderer.send :include, Redcarpet::Render::SmartyPants if @redcarpet_extensions[:smart] | |
markdown = Redcarpet::Markdown.new(@renderer.new(@redcarpet_extensions), @redcarpet_extensions) | |
# markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true) | |
blocks = File.read("c:/redcarpet/debug/input_1.md") | |
outs = markdown.render(blocks) | |
# puts outs | |
File.write("c:/redcarpet/debug/out_1.html", outs) | |
puts "DONE !" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment