aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--plugins/image_tag.rb18
-rw-r--r--plugins/include_code.rb2
-rw-r--r--plugins/octopress_filters.rb33
3 files changed, 44 insertions, 9 deletions
diff --git a/plugins/image_tag.rb b/plugins/image_tag.rb
index 7be4003d..25a38df5 100644
--- a/plugins/image_tag.rb
+++ b/plugins/image_tag.rb
@@ -17,12 +17,20 @@ module Jekyll
@img = nil
@title = nil
@class = ''
+ @width = ''
+ @height = ''
def initialize(tag_name, markup, tokens)
- if markup =~ /(\S.*\s+)?(https?:\/\/|\/)(\S+)(\s+.+)?/i
- @class = $1
+ if markup =~ /(\S.*\s+)?(https?:\/\/|\/)(\S+)(\s+\d+\s+\d+)?(\s+.+)?/i
+ @class = $1 || ''
@img = $2 + $3
- @title = $4
+ if $5
+ @title = $5.strip
+ end
+ if $4 =~ /\s*(\d+)\s+(\d+)/
+ @width = $1
+ @height = $2
+ end
end
super
end
@@ -30,9 +38,9 @@ module Jekyll
def render(context)
output = super
if @img
- "<img class='#{@class}' src='#{@img}' alt='#{@title}' title='#{@title}'>"
+ "<img class='#{@class}' src='#{@img}' width='#{@width}' height='#{@height}' alt='#{@title}' title='#{@title}'>"
else
- "Error processing input, expected syntax: {% img [class name(s)] /url/to/image [title text] %}"
+ "Error processing input, expected syntax: {% img [class name(s)] /url/to/image [width height] [title text] %}"
end
end
end
diff --git a/plugins/include_code.rb b/plugins/include_code.rb
index 93db78a3..ec72006c 100644
--- a/plugins/include_code.rb
+++ b/plugins/include_code.rb
@@ -38,7 +38,7 @@ module Jekyll
end
def render(context)
- code_dir = (context.registers[:site].config['code_dir'] || 'downloads/code')
+ code_dir = (context.registers[:site].config['code_dir'].sub(/^\//,'') || 'downloads/code')
code_path = (Pathname.new(context.registers[:site].source) + code_dir).expand_path
file = code_path + @file
diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb
index 7d73bdec..f2a5073b 100644
--- a/plugins/octopress_filters.rb
+++ b/plugins/octopress_filters.rb
@@ -26,10 +26,37 @@ module OctopressFilters
# code snippet
# ```
def backtick_codeblock(input)
- input.gsub /<p>`{3}\s(\w+)<\/p>\n\n<pre><code>([^<]+)<\/code><\/pre>\n\n<p>`{3}<\/p>/m do
+ # Markdown support
+ input = input.gsub /<p>`{3}\s*(\w+)?<\/p>\s*<pre><code>\s*(.+?)\s*<\/code><\/pre>\s*<p>`{3}<\/p>/m do
lang = $1
- str = $2.gsub('&lt;','<').gsub('&gt;','>')
- highlight(str, lang)
+ if lang != ''
+ str = $2.gsub('&lt;','<').gsub('&gt;','>')
+ highlight(str, lang)
+ else
+ "<pre><code>#{$2}</code></pre>"
+ end
+ end
+
+ # Textile support
+ input = input.gsub /<p>`{3}\s*(\w+)?<br\s*\/>\n(.+?)`{3}<\/p>/m do
+ lang = $1
+ str = $2.gsub('&lt;','<').gsub('&gt;','>').gsub(/^\s{4}/, '').gsub(/(<br\s\/>)?$/, '')
+ if lang != ''
+ highlight(str, lang)
+ else
+ "<pre><code>#{$2}</code></pre>"
+ end
+ end
+
+ # Regular HTML support
+ input.gsub /^`{3}\s*(\w+)?\n(.+?)\n`{3}/m do
+ lang = $1
+ str = $2.gsub(/^\s{4}/, '')
+ if lang != ''
+ highlight(str, lang)
+ else
+ "<pre><code>#{$2.gsub('<','&lt;').gsub('>','&gt;')}</code></pre>"
+ end
end
end