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!('« ', '«&nbsp;')
        text.gsub!(/ ([:;»!?])/, '&nbsp;\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

Version Path
html-pipeline-linuxfr-0.15.7 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.15.6 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.15.5 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.15.4 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.15.3 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.14.30 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.15.2 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.15.1 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.14.29 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.15.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.14.28 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.14.27 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.14.26 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.14.25 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.14.24 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.14.23 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.14.22 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.14.21 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.14.20 lib/html/pipeline/markdown_filter.rb
html-pipeline-linuxfr-0.14.19 lib/html/pipeline/markdown_filter.rb