Sha256: b70963f4c8a9d0e66fb707360cd9026b2a820ee8afb24b75fe6dd999b12328ce
Contents?: true
Size: 1.77 KB
Versions: 24
Compression:
Stored size: 1.77 KB
Contents
# encoding: utf-8 require 'redcarpet' require 'cgi' module HTML class Pipeline # LinuxFr Flavored Markdown class LFMarkdown < Redcarpet::Render::HTML PARSER_OPTIONS = { :no_intra_emphasis => true, :tables => true, :fenced_code_blocks => true, :autolink => true, :strikethrough => true, :superscript => true, :footnotes => true, } HTML_OPTIONS = { :filter_html => true, :no_styles => true, :hard_wrap => true, :xhtml => true, } def initialize(extensions={}) super extensions.merge(HTML_OPTIONS) end def header(text, header_level, anchor=nil) l = header_level + 1 "<h#{l}>#{text}</h#{l}>\n" end def strikethrough(text) "<s>#{text}</s>" end def image(link, title, alt_text) return "" if link.blank? ::Image.new(link, title, alt_text).to_html # FIXME end def normal_text(text) text = CGI.escapeHTML(text) text.gsub!('« ', '« ') text.gsub!(/ ([:;»!?])/, ' \1') text.gsub!(' -- ', '—') text.gsub!('...', '…') text end end # HTML Filter that converts Markdown text into HTML and converts into a # DocumentFragment. This is different from most filters in that it can take a # non-HTML as input. It must be used as the first filter in a pipeline. # # This filter does not write any additional information to the context hash. class MarkdownFilter < TextFilter def call lfm = Redcarpet::Markdown.new LFMarkdown, LFMarkdown::PARSER_OPTIONS lfm.render @text end end end end
Version data entries
24 entries across 24 versions & 1 rubygems