Class: Jekyll::HighlightBlock

Inherits:
Liquid::Block
  • Object
show all
Includes:
Liquid::StandardFilters
Defined in:
lib/jekyll/tags/highlight.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, lang, tokens) ⇒ HighlightBlock

Returns a new instance of HighlightBlock.



6
7
8
9
# File 'lib/jekyll/tags/highlight.rb', line 6

def initialize(tag_name, lang, tokens)
  super
  @lang = lang.strip
end

Instance Method Details

#render(context) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/jekyll/tags/highlight.rb', line 11

def render(context)
  if Jekyll.pygments
    render_pygments(context, super.to_s)
  else
    render_codehighlighter(context, super.to_s)
  end
end

#render_codehighlighter(context, code) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/jekyll/tags/highlight.rb', line 23

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

#render_pygments(context, code) ⇒ Object



19
20
21
# File 'lib/jekyll/tags/highlight.rb', line 19

def render_pygments(context, code)
  "<notextile>" + Albino.new(code, @lang).to_s + "</notextile>"
end