Jim Schubert, Software Developer
So, I wrote a plugin for Jekyll to use Syntax Highlighter. It looks like I'd have to generate the blog before pushing to github. I'm not trying to mess around with all of that right now, so I thought I'd just post the plugin for future reference. # syntax.rb
module Jekyll

  class SyntaxBlock < Liquid::Block
    include Liquid::StandardFilters

    # We need a language, but the linenos argument is optional.
    SYNTAX = /(\w+)\s?([\w\s=,]+)*/

    def initialize(tag_name, markup, tokens)
      super      
      if markup =~ SYNTAX
		@lang = $1
		if defined? $2
		  tmp_options = {}
			$2.split.each do |opt|
				if opt.to_s.include? "="
					key, value = opt.split('=')
					if value.nil?
						value = "true"
					else
					  	value = value.gsub(/['"]/,'')
					  	if value.to_s.include? ","
					  		value = "[#{value}]" 
					  	end
					end # value.nil?
				end # opt.include? "="
				tmp_options[key] = value.to_s
			end # $2.split.each do |opt||
			@options = tmp_options
		else
		  @options = {}
		end #if defined? 2      
      else
        raise SyntaxError.new("Syntax Error in 'highlight' - Valid syntax: highlight  [linenos]")
      end
      @options[:brush] = @lang
    end

    def render(context)
        render_codehighlighter(context, super.join)
    end

    def render_codehighlighter(context, code)
      cls_nm = @options.map{|k,v| "#{k}: #{v}"}.join(';')
      #The div is required because RDiscount blows ass
      <<-HTML
#{h(code).strip}
  
HTML end end end Liquid::Template.register_tag('syntax', Jekyll::SyntaxBlock)
198 words
May 28,
2011
Fork me on GitHub