gem 'redcarpet'
gem 'rouge' // for themes
module MarkdownHelper
require 'redcarpet'
require 'rouge'
require 'rouge/plugins/redcarpet'
class HTML < Redcarpet::Render::HTML
include Rouge::Plugins::Redcarpet
end
def markdown(text)
render_options = {
# filer_html: true,
hard_wrap: true,
link_attributes: { rel: 'nofollow' },
prettify: true
}
#renderer = Redcarpet::Render::HTML.new(render_options)
renderer = HTML.new(render_options)
extras = {
no_intra_emphasis: true,
tables: true, // support table
fenced_code_blocks: true,
autolink: true,
disable_indented_code_blocks: true,
strikethrough: true,
lax_spacing: true,
space_after_headers: true,
superscript: true,
underline: true,
highlight: true,
quote: true,
footnotes: true,
}
markdown = Redcarpet::Markdown.new(renderer, extras)
raw markdown.render(text)
end
end
include MarkdownHelper
usage: markdown(text)
css (app/assets/stylesheets
)
*= require rouge
*= require github_markdown
<%= Rouge::Themes::Github.render(scope: '.highlight') %>
copy table, blockquote, code format from github.css
<div class="markdown-body"> // enable github_markdown.css
<%= markdown(v) %>
</div>
Issues: