Sha256: ae804051da29abd74de98801eb9a349f2947661318cb89ea23462dbab2779c70

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

require 'html/pipeline'
require 'filters/filters'

Dir[File.join("#{File.expand_path(File.dirname(__FILE__))}", "filters", "pre", "*.rb")].each do |file|
  require file
end

Dir[File.join("#{File.expand_path(File.dirname(__FILE__))}", "filters", "post", "*.rb")].each do |file|
  require file
end

class ExtendedMarkdownFilter < HTML::Pipeline::MarkdownFilter
  include Filters::PreFilter
  include Filters::PostFilter

  AMF_CURLY_TAGS = %w(intro mac windows linux all tip warning error).join('|')

  def initialize(text, context = nil, result = nil)
    if defined?(Jekyll) && context[:amf_use_blocks]
      require 'jekyll-override'
    end

    if context[:amf_use_blocks]
      text = self.class.convert_curly_to_bracket(text)
    end

    Filters.context = context

    # do preprocessing, then call HTML::Pipeline::Markdown
    format_command_line!    text
    format_helper!          text

    super text, context, result
  end

  def self.convert_curly_to_bracket(text)
    text = text.gsub(/\{\{\s*#(#{AMF_CURLY_TAGS})\s*\}\}/, '[[#\1]]')
    text = text.gsub(/\{\{\s*\/(#{AMF_CURLY_TAGS})\s*\}\}/, '[[/\1]]')
    text = text.gsub(/\{\{\s*(octicon-\S+\s*[^\}]+)\s*\}\}/,  '[[\1]]')

    text
  end

  def call
    # initialize HTML::Pipeline::Markdown, then do post-processing
    html = super

    format_intro!           html
    format_os_blocks!       html
    format_admonitions!     html
    format_octicons!        html

    html
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
extended-markdown-filter-0.3.0 lib/extended-markdown-filter.rb