From 83d87f98cc22dd00bc1ececcb3022ae9ccb964cb Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sat, 20 Aug 2011 20:24:51 -0400 Subject: 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(-) (limited to 'plugins') diff --git a/plugins/code_block.rb b/plugins/code_block.rb index d82893ea..4d7ca6bb 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 d910c3e6..046f6245 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" -- cgit v1.2.1