aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--plugins/backtick_code_block.rb7
-rw-r--r--plugins/code_block.rb8
-rw-r--r--plugins/include_code.rb6
-rw-r--r--plugins/octopress_filters.rb44
-rw-r--r--plugins/pygments_code.rb6
-rw-r--r--plugins/raw.rb4
6 files changed, 38 insertions, 37 deletions
diff --git a/plugins/backtick_code_block.rb b/plugins/backtick_code_block.rb
index 8e2c1141..ae4a0472 100644
--- a/plugins/backtick_code_block.rb
+++ b/plugins/backtick_code_block.rb
@@ -1,10 +1,9 @@
require './plugins/pygments_code'
module BacktickCodeBlock
- include HighlightCode
AllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/i
LangCaption = /([^\s]+)\s*(.+)?/i
- def render_code_block(input)
+ def self.render_code_block(input)
@options = nil
@caption = nil
@lang = nil
@@ -26,7 +25,7 @@ module BacktickCodeBlock
str = str.gsub(/^( {4}|\t)/, '')
end
if @lang.nil? || @lang == 'plain'
- code = tableize_code(str.gsub('<','&lt;').gsub('>','&gt;'))
+ code = HighlightCode::tableize_code(str.gsub('<','&lt;').gsub('>','&gt;'))
"<figure class='code'>#{@caption}#{code}</figure>"
else
if @lang.include? "-raw"
@@ -34,7 +33,7 @@ module BacktickCodeBlock
raw += str
raw += "\n```\n"
else
- code = highlight(str, @lang)
+ code = HighlightCode::highlight(str, @lang)
"<figure class='code'>#{@caption}#{code}</figure>"
end
end
diff --git a/plugins/code_block.rb b/plugins/code_block.rb
index 46620d86..539a3475 100644
--- a/plugins/code_block.rb
+++ b/plugins/code_block.rb
@@ -47,8 +47,6 @@ require './plugins/raw'
module Jekyll
class CodeBlock < Liquid::Block
- include HighlightCode
- include TemplateWrapper
CaptionUrlTitle = /(\S[\S\s]*)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/i
Caption = /(\S[\S\s]*)/
def initialize(tag_name, markup, tokens)
@@ -79,11 +77,11 @@ module Jekyll
source = "<figure class='code'>"
source += @caption if @caption
if @filetype
- source += "#{highlight(code, @filetype)}</figure>"
+ source += "#{HighlightCode::highlight(code, @filetype)}</figure>"
else
- source += "#{tableize_code(code.lstrip.rstrip.gsub(/</,'&lt;'))}</figure>"
+ source += "#{HighlightCode::tableize_code(code.lstrip.rstrip.gsub(/</,'&lt;'))}</figure>"
end
- source = safe_wrap(source)
+ source = TemplateWrapper::safe_wrap(source)
source = context['pygments_prefix'] + source if context['pygments_prefix']
source = source + context['pygments_suffix'] if context['pygments_suffix']
source
diff --git a/plugins/include_code.rb b/plugins/include_code.rb
index 41f30337..a61d06cf 100644
--- a/plugins/include_code.rb
+++ b/plugins/include_code.rb
@@ -27,8 +27,6 @@ require 'pathname'
module Jekyll
class IncludeCodeTag < Liquid::Tag
- include HighlightCode
- include TemplateWrapper
def initialize(tag_name, markup, tokens)
@title = nil
@file = nil
@@ -62,8 +60,8 @@ module Jekyll
title = @title ? "#{@title} (#{file.basename})" : file.basename
url = "/#{code_dir}/#{@file}"
source = "<figure class='code'><figcaption><span>#{title}</span> <a href='#{url}'>download</a></figcaption>\n"
- source += "#{highlight(code, @filetype)}</figure>"
- safe_wrap(source)
+ source += "#{HighlightCode::highlight(code, @filetype)}</figure>"
+ TemplateWrapper::safe_wrap(source)
end
end
end
diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb
index aad5bf9f..bac6768d 100644
--- a/plugins/octopress_filters.rb
+++ b/plugins/octopress_filters.rb
@@ -7,32 +7,38 @@ 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)
+ def self.pre_filter(page)
+ if page.ext.match('html|textile|markdown|md|haml|slim|xml')
+ input = BacktickCodeBlock::render_code_block(page.content)
+ page.content = input.gsub /(<figure.+?>.+?<\/figure>)/m do
+ TemplateWrapper::safe_wrap($1)
+ end
end
end
- def post_filter(input)
- input = unwrap(input)
- RubyPants.new(input).to_html
+ def self.post_filter(page)
+ if page.ext.match('html|textile|markdown|md|haml|slim|xml')
+ input = TemplateWrapper::unwrap(page.content)
+ page.content = RubyPants.new(input).to_html
+ end
end
-end
-module Jekyll
- class ContentFilters < PageHooks
- include OctopressFilters
+ class PageFilters < Octopress::Hooks::Page
+ def pre_render(page)
+ OctopressFilters::pre_filter(page)
+ end
+
+ def post_render(page)
+ OctopressFilters::post_filter(page)
+ end
+ end
+
+ class PostFilters < Octopress::Hooks::Post
def pre_render(post)
- if post.ext.match('html|textile|markdown|md|haml|slim|xml')
- post.content = pre_filter(post.content)
- end
+ OctopressFilters::pre_filter(post)
end
+
def post_render(post)
- if post.ext.match('html|textile|markdown|md|haml|slim|xml')
- post.content = post_filter(post.content)
- end
+ OctopressFilters::post_filter(post)
end
end
end
diff --git a/plugins/pygments_code.rb b/plugins/pygments_code.rb
index 8b851a3b..c0f4de92 100644
--- a/plugins/pygments_code.rb
+++ b/plugins/pygments_code.rb
@@ -6,7 +6,7 @@ PYGMENTS_CACHE_DIR = File.expand_path('../../.pygments-cache', __FILE__)
FileUtils.mkdir_p(PYGMENTS_CACHE_DIR)
module HighlightCode
- def highlight(str, lang)
+ def self.highlight(str, lang)
lang = 'ruby' if lang == 'ru'
lang = 'objc' if lang == 'm'
lang = 'perl' if lang == 'pl'
@@ -15,7 +15,7 @@ module HighlightCode
tableize_code(str, lang)
end
- def pygments(code, lang)
+ def self.pygments(code, lang)
if defined?(PYGMENTS_CACHE_DIR)
path = File.join(PYGMENTS_CACHE_DIR, "#{lang}-#{Digest::MD5.hexdigest(code)}.html")
if File.exist?(path)
@@ -33,7 +33,7 @@ module HighlightCode
end
highlighted_code
end
- def tableize_code (str, lang = '')
+ def self.tableize_code (str, lang = '')
table = '<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers">'
code = ''
str.lines.each_with_index do |line,index|
diff --git a/plugins/raw.rb b/plugins/raw.rb
index 4b002625..e97c9459 100644
--- a/plugins/raw.rb
+++ b/plugins/raw.rb
@@ -3,11 +3,11 @@
# Purpose: This is useful for preventing Markdown and Textile from being too aggressive and incorrectly parsing in-line HTML.
module TemplateWrapper
# Wrap input with a <div>
- def safe_wrap(input)
+ def self.safe_wrap(input)
"<div class='bogus-wrapper'><notextile>#{input}</notextile></div>"
end
# This must be applied after the
- def unwrap(input)
+ def self.unwrap(input)
input.gsub /<div class='bogus-wrapper'><notextile>(.+?)<\/notextile><\/div>/m do
$1
end