From 6b586af8a5ca64f74537b6341ab37e5bfe8faf91 Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sat, 20 Aug 2011 18:39:00 -0400 Subject: [PATCH 1/3] centralized pygments aliases into pygments_code.rb. Added alias for .ru (ruby), which sort of fixes #108 --- plugins/code_block.rb | 3 --- plugins/include_code.rb | 3 --- plugins/pygments_code.rb | 4 ++++ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/code_block.rb b/plugins/code_block.rb index 55267a3..d82893e 100644 --- a/plugins/code_block.rb +++ b/plugins/code_block.rb @@ -77,9 +77,6 @@ module Jekyll source += @caption if @caption source = context['pygments_prefix'] + source if context['pygments_prefix'] if @filetype - @filetype = 'objc' if @filetype == 'm' - @filetype = 'perl' if @filetype == 'pl' - @filetype = 'yaml' if @filetype == 'yml' source += " #{highlight(code, @filetype)}" else source += "#{tableize_code(code.lstrip.rstrip.gsub(/" diff --git a/plugins/include_code.rb b/plugins/include_code.rb index e064fe2..d910c3e 100644 --- a/plugins/include_code.rb +++ b/plugins/include_code.rb @@ -53,9 +53,6 @@ module Jekyll Dir.chdir(code_path) do code = file.read @filetype = file.extname.sub('.','') - @filetype = 'objc' if @filetype == 'm' - @filetype = 'perl' if @filetype == 'pl' - @filetype = 'yaml' if @filetype == 'yml' title = @title ? "#{@title} (#{file.basename})" : file.basename url = "#{context.registers[:site].config['url']}/#{code_dir}/#{@file}" source = "
#{title} download
\n" diff --git a/plugins/pygments_code.rb b/plugins/pygments_code.rb index 1930ec8..67ce8c3 100644 --- a/plugins/pygments_code.rb +++ b/plugins/pygments_code.rb @@ -7,6 +7,10 @@ FileUtils.mkdir_p(PYGMENTS_CACHE_DIR) module HighlightCode def highlight(str, lang) + lang = 'ruby' if lang == 'ru' + lang = 'objc' if lang == 'm' + lang = 'perl' if lang == 'pl' + lang = 'yaml' if lang == 'yml' str = pygments(str, lang).match(/
(.+)<\/pre>/m)[1].to_s.gsub(/ *$/, '') #strip out divs 
tableize_code(str, lang) end From d5e4bf2d8c92fa754b8318fa751f612822e38b58 Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sat, 20 Aug 2011 18:39:35 -0400 Subject: [PATCH 2/3] added test for .ru pygments alias --- source/test/code/markdown/index.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/test/code/markdown/index.markdown b/source/test/code/markdown/index.markdown index 7e3e39b..dae78c2 100644 --- a/source/test/code/markdown/index.markdown +++ b/source/test/code/markdown/index.markdown @@ -27,3 +27,7 @@ fi done unset i {% endcodeblock %} + +{% codeblock config.ru %} +Bunch of ruby code +{% endcodeblock %} From cbd6f8d8dee52930b923dc2277f0677e95dd6bc8 Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sat, 20 Aug 2011 20:24:51 -0400 Subject: [PATCH 3/3] added option to force syntax highlighting language, example: {% include_code file lang:ruby %}. Fixes #108 --- plugins/code_block.rb | 7 ++++++- plugins/include_code.rb | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/code_block.rb b/plugins/code_block.rb index d82893e..4d7ca6b 100644 --- a/plugins/code_block.rb +++ b/plugins/code_block.rb @@ -53,7 +53,12 @@ module Jekyll def initialize(tag_name, markup, tokens) @title = nil @caption = nil + @filetype = nil @highlight = true + if markup =~ /\s+lang:(\w+)/i + @filetype = $1 + markup = markup.sub(/\s+lang:\w+\s*/i,'') + end if markup =~ CaptionUrlTitle @file = $1 @caption = "
#{$1}#{$4}
" @@ -64,7 +69,7 @@ module Jekyll @file = $1 @caption = "
#{$1}
\n" end - if @file =~ /\S[\S\s]*\w+\.(\w+)/ + if @file =~ /\S[\S\s]*\w+\.(\w+)/ && @filetype.nil? @filetype = $1 end super diff --git a/plugins/include_code.rb b/plugins/include_code.rb index d910c3e..046f624 100644 --- a/plugins/include_code.rb +++ b/plugins/include_code.rb @@ -30,6 +30,10 @@ module Jekyll def initialize(tag_name, markup, tokens) @title = nil @file = nil + if markup.strip =~ /\s+lang:(\w+)/i + @filetype = $1 + markup = markup.strip.sub(/\s+lang:\w+\s*/i,'') + end if markup.strip =~ /(.*)?(\s+|^)(\/*\S+)/i @title = $1 || nil @file = $3 @@ -52,7 +56,7 @@ module Jekyll Dir.chdir(code_path) do code = file.read - @filetype = file.extname.sub('.','') + @filetype = file.extname.sub('.','') if @filetype.nil? title = @title ? "#{@title} (#{file.basename})" : file.basename url = "#{context.registers[:site].config['url']}/#{code_dir}/#{@file}" source = "
#{title} download
\n"