require './plugins/backtick_code_block'
require './plugins/post_filters'
require './plugins/raw'
require 'rubypants'
module OctopressFilters
include BacktickCodeBlock
include TemplateWrapper
def pre_filter(input)
input = render_code_block(input)
input.gsub /(<figure.+?>.+?<\/figure>)/m do
safe_wrap($1)
end
end
def post_filter(input)
input = unwrap(input)
RubyPants.new(input).to_html
end
end
module Jekyll
class ContentFilters < PostFilter
include OctopressFilters
def pre_render(post)
post.content = pre_filter(post.content)
end
def post_render(post)
post.content = post_filter(post.content)
end
end
end
module OctopressLiquidFilters
def excerpt(input)
if input.index(/<!--\s*more\s*-->/i)
input.split(/<!--\s*more\s*-->/i)[0]
else
input
end
end
def has_excerpt(input)
input =~ /<!--\s*more\s*-->/i ? true : false
end
def summary(input)
if input.index(/\n\n/)
input.split(/\n\n/)[0]
else
input
end
end
def raw_content(input)
/<div class="entry-content">(?<content>[\s\S]*?)<\/div>\s*<(footer|\/article)>/ =~ input
return (content.nil?) ? input : content
end
def expand_urls(input, url='')
url ||= '/'
input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/[^\"'>]*)/ do
$1+url+$3
end
end
def strip_slash(input)
if input =~ /(.+)\/$|^\/$/
input = $1
end
input
end
def shorthand_url(input)
input.gsub /(https?:\/\/)(\S+)/ do
$2
end
end
def titlecase(input)
input.titlecase
end
def datetime(date)
if date.class == String
date = Time.parse(date)
end
date
end
def ordinalize(date)