Module: Haml::Filters::Code

Includes:
Base
Defined in:
lib/middleman-syntax/haml_monkey_patch.rb

Instance Method Summary collapse

Instance Method Details

#render(code) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/middleman-syntax/haml_monkey_patch.rb', line 8

def render(code)
  code = code.encode(Encoding::UTF_8)

  # Allow language to be specified via a special comment like:
  #  # lang: ruby
  if code.lines.first =~ /\A\s*#\s*lang:\s*(\w+)$/
      language = $1
    code = code.lines.to_a[1..-1].join # Strip first line
  end

  Middleman::Syntax::Highlighter.highlight(code, language)
end