Sha256: 472f01fb3e8f2d0c49793c7e10026e2ab21ae4786fcd85810f3a892600b39a15

Contents?: true

Size: 593 Bytes

Versions: 3

Compression:

Stored size: 593 Bytes

Contents

module Filters
  module PreFilter
    def format_helper(text)
      prefix = '<p'

      text.gsub /\n?``` helper(.+?)```/m do |block|
        block.gsub! /^``` helper\s*/, ''
        block.gsub! /^```$/, ''

        header = ''
        block.gsub! /^#### (.+?)$/ do
          header = $1.strip
          ''
        end

        content = block.strip
        content = "<p>#{content}</p>" unless content[0, prefix.length] == prefix
        content = "<div class='helper'><h4 class='header'><a href='#'>#{header}</a></h4><div class='content'>#{content}</div></div>"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
extended-markdown-filter-0.4.4 lib/filters/pre/helper.rb
extended-markdown-filter-0.4.3 lib/filters/pre/helper.rb
extended-markdown-filter-0.4.2 lib/filters/pre/helper.rb