Created
December 4, 2013 03:15
-
-
Save shu0115/7781776 to your computer and use it in GitHub Desktop.
Markdown/シンタックスハイライト導入 - redcarpet/coderay ref: http://qiita.com/shu_0115/items/476a51cb4751515f3ac2
This file contains 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
# Markdown & Syntax Highlight | |
gem 'redcarpet' | |
gem 'coderay' |
This file contains 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
bundle install |
This file contains 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
module ApplicationHelper | |
class HTMLwithCoderay < Redcarpet::Render::HTML | |
def block_code(code, language) | |
case language.to_s | |
when 'rb' | |
lang = 'ruby' | |
when 'yml' | |
lang = 'yaml' | |
when '' | |
# 空欄のままだと「Invalid id given:」エラー | |
lang = 'md' | |
else | |
lang = language | |
end | |
CodeRay.scan(code, lang).div | |
end | |
end | |
def markdown(text) | |
html_render = HTMLwithCoderay.new(filter_html: true, hard_wrap: true) | |
options = { | |
autolink: true, | |
space_after_headers: true, | |
fenced_code_blocks: true, | |
} | |
markdown = Redcarpet::Markdown.new(html_render, options) | |
markdown.render(text) | |
end | |
end |
This file contains 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
= markdown(@post.body).html_safe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment