Table: RailsNotes
User: dreamable
Created at: 2021-01-12 10:41:30 UTC
Updated at: 2021-01-14 23:33:05 UTC
Reference:(Table ID 3, Record ID 12)

标题 :
Markdown
笔记 :

Guide
Install redcarpet

  • Gemfile
  gem 'redcarpet'
  gem 'rouge' // for themes
  • app/helpers/markdown_helper.rb
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
  • application_controller.rb
  include MarkdownHelper
  • usage: markdown(text)

  • Rouge themes

    • we use GitHub
  • css (app/assets/stylesheets)

    • application.css
     *= require rouge
     *= require github_markdown
    
    • rouge.scss.erb
    <%= 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:

  • List with code not working well, must have new line between
Tag: