Sha256: 4d5c87ec8b2603643db11f818feb23b9035506a863bc8bf5827c880053aac56b
Contents?: true
Size: 1.2 KB
Versions: 16
Compression:
Stored size: 1.2 KB
Contents
begin require 'rinku' require 'kramdown' require 'sanitize' module Snails module Markdown MARKDOWN_OPTS = { input: 'GFM', enable_coderay: true, parse_block_html: false, line_width: 72, coderay_tab_width: 2, coderay_line_numbers: nil, coderay_default_lang: 'bash', coderay_css: :class } SANITIZE_OPTS = Sanitize::Config::RELAXED SANITIZE_OPTS[:elements] = %w( p br a span sub sup strong em div hr abbr ul ol li blockquote pre code kbd h1 h2 h3 h4 h5 h6 img object param del ) SANITIZE_OPTS[:attributes] = { :all => ['class', 'style', 'title', 'id'], 'a' => ['href', 'rel', 'name'], 'img' => ['src', 'title', 'alt', 'width', 'height'] } SANITIZE_OPTS[:add_attributes] = { 'a' => {'rel' => 'nofollow', 'target' => '_blank'} } def render_markdown(str, options = {}) html = Kramdown::Document.new(str, MARKDOWN_OPTS).to_html html = Rinku.auto_link(html, :urls) Sanitize.clean(html, SANITIZE_OPTS) end end end rescue LoadError => e puts "Cannot load Snails's markdown lib. (#{e.class})" puts "You need the `kramdown`, `rinku` and `sanitize` gems for this." end
Version data entries
16 entries across 16 versions & 1 rubygems