Whitelist three Pygments options.

- startinline
- hl_lines
- linenos
This commit is contained in:
Parker Moore 2014-07-29 14:20:49 -04:00
parent 502f7991ad
commit a4c9925e99
1 changed files with 13 additions and 2 deletions

View File

@ -44,9 +44,11 @@ eos
suffix = context["highlighter_suffix"] || "" suffix = context["highlighter_suffix"] || ""
code = super.to_s.strip code = super.to_s.strip
is_safe = !!context.registers[:site].safe
output = case context.registers[:site].highlighter output = case context.registers[:site].highlighter
when 'pygments' when 'pygments'
render_pygments(code) render_pygments(code, is_safe)
when 'rouge' when 'rouge'
render_rouge(code) render_rouge(code)
else else
@ -57,8 +59,17 @@ eos
prefix + rendered_output + suffix prefix + rendered_output + suffix
end end
def render_pygments(code) def render_pygments(code, is_safe)
require 'pygments' require 'pygments'
if is_safe
@options = {
:startinline => @options.fetch(:startinline, nil),
:hl_lines => @options.fetch(:hl_lines, nil),
:linenos => @options.fetch(:linenos, nil)
}
end
@options[:encoding] = 'utf-8' @options[:encoding] = 'utf-8'
highlighted_code = Pygments.highlight(code, :lexer => @lang, :options => @options) highlighted_code = Pygments.highlight(code, :lexer => @lang, :options => @options)