Sha256: 1da5c29036ea7d5be2e28328979c0e61d7f5955cd2ad2936d99912c09d928585
Contents?: true
Size: 1.48 KB
Versions: 49
Compression:
Stored size: 1.48 KB
Contents
require 'digest/md5' module Haml::Filters remove_filter("Markdown") module Markdown include Haml::Filters::Base # require "rdiscount" def render(text) return "" if text.nil? text = text.encode('UTF-8') kramdown text end def redcarpet(text) markdown = Redcarpet::Markdown.new( Redcarpet::Render::HTML, no_intra_emphasis: true, tables: true, 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.render text end def kramdown(text) Kramdown::Document.new(text).to_html end # taken from https://help.github.com/articles/github-flavored-markdown def gfm(text) # Extract pre blocks extractions = {} text.gsub!(%r{<pre>.*?</pre>}m) do |match| md5 = Digest::MD5.hexdigest(match) extractions[md5] = match "{gfm-extraction-#{md5}}" end # in very clear cases, let newlines become <br /> tags text.gsub!(/^[\w\<][^\n]*\n+/) do |x| x =~ /\n{2}/ ? x : (x.strip!; x << " \n") end # Insert pre block extractions text.gsub!(/\{gfm-extraction-([0-9a-f]{32})\}/) do "\n\n" + extractions[$1] end text end end end
Version data entries
49 entries across 49 versions & 1 rubygems