Sha256: 49bdfa4d1352baf88d94991d9003d26c827effa651d127b83a584b42338f34bd

Contents?: true

Size: 595 Bytes

Versions: 6

Compression:

Stored size: 595 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

6 entries across 6 versions & 1 rubygems

Version Path
extended-markdown-filter-0.4.1 lib/filters/pre/helper.rb
extended-markdown-filter-0.4.0 lib/filters/pre/helper.rb
extended-markdown-filter-0.3.8 lib/filters/pre/helper.rb
extended-markdown-filter-0.3.7 lib/filters/pre/helper.rb
extended-markdown-filter-0.3.6 lib/filters/pre/helper.rb
extended-markdown-filter-0.3.5 lib/filters/pre/helper.rb