centralized pygments aliases into pygments_code.rb. Added alias for .ru (ruby), which sort of fixes #108

This commit is contained in:
Brandon Mathis 2011-08-20 18:39:00 -04:00
parent 1722c503f7
commit 6b586af8a5
3 changed files with 4 additions and 6 deletions

View File

@ -77,9 +77,6 @@ module Jekyll
source += @caption if @caption source += @caption if @caption
source = context['pygments_prefix'] + source if context['pygments_prefix'] source = context['pygments_prefix'] + source if context['pygments_prefix']
if @filetype if @filetype
@filetype = 'objc' if @filetype == 'm'
@filetype = 'perl' if @filetype == 'pl'
@filetype = 'yaml' if @filetype == 'yml'
source += " #{highlight(code, @filetype)}</figure></div>" source += " #{highlight(code, @filetype)}</figure></div>"
else else
source += "#{tableize_code(code.lstrip.rstrip.gsub(/</,'&lt;'))}</figure></div>" source += "#{tableize_code(code.lstrip.rstrip.gsub(/</,'&lt;'))}</figure></div>"

View File

@ -53,9 +53,6 @@ module Jekyll
Dir.chdir(code_path) do Dir.chdir(code_path) do
code = file.read code = file.read
@filetype = file.extname.sub('.','') @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 title = @title ? "#{@title} (#{file.basename})" : file.basename
url = "#{context.registers[:site].config['url']}/#{code_dir}/#{@file}" url = "#{context.registers[:site].config['url']}/#{code_dir}/#{@file}"
source = "<div><figure role=code><figcaption><span>#{title}</span> <a href='#{url}'>download</a></figcaption>\n" source = "<div><figure role=code><figcaption><span>#{title}</span> <a href='#{url}'>download</a></figcaption>\n"

View File

@ -7,6 +7,10 @@ FileUtils.mkdir_p(PYGMENTS_CACHE_DIR)
module HighlightCode module HighlightCode
def highlight(str, lang) 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>(.+)<\/pre>/m)[1].to_s.gsub(/ *$/, '') #strip out divs <div class="highlight"> str = pygments(str, lang).match(/<pre>(.+)<\/pre>/m)[1].to_s.gsub(/ *$/, '') #strip out divs <div class="highlight">
tableize_code(str, lang) tableize_code(str, lang)
end end