Sha256: f5e70bfd04ce9e97a30bfcef9bf73c9c884869aa945eea0a35d6a5322cca5dec
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
Contents
module Jekyll class HighlightBlock < Liquid::Block include Liquid::StandardFilters # we need a language, but the linenos argument is optional. SYNTAX = /(\w+)\s?(:?linenos)?\s?/ def initialize(tag_name, markup, tokens) super if markup =~ SYNTAX @lang = $1 if defined? $2 # additional options to pass to Albino. @options = { 'O' => 'linenos=table,encoding=utf8,style=native' } else @options = { 'O' => 'encoding=utf8,style=native' } end else raise SyntaxError.new("Syntax Error in 'highlight' - Valid syntax: highlight <lang> [linenos]") end end def render(context) if Jekyll.pygments render_pygments(context, super.to_s) else render_codehighlighter(context, super.to_s) end end def render_pygments(context, code) if Jekyll.content_type == :markdown return "\n" + Albino.new(code, @lang).to_s(@options) + "\n" else content = "\n<notextile>\n" + Albino.new(code, @lang).to_s(@options) + "\n</notextile>\n" content end end def render_codehighlighter(context, code) #The div is required because RDiscount blows ass <<-HTML <div> <pre> <code class='#{@lang}'>#{h(code).strip}</code> </pre> </div> HTML end end end Liquid::Template.register_tag('highlight', Jekyll::HighlightBlock)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jsjohnst-jekyll-0.4.1.999.6 | lib/jekyll/tags/highlight.rb |