From a4c9925e995da4d96b528207ccee2ef2bc97b02c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 29 Jul 2014 14:20:49 -0400 Subject: [PATCH] Whitelist three Pygments options. - startinline - hl_lines - linenos --- lib/jekyll/tags/highlight.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index f7ca2dcd..52e62d3b 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -44,9 +44,11 @@ eos suffix = context["highlighter_suffix"] || "" code = super.to_s.strip + is_safe = !!context.registers[:site].safe + output = case context.registers[:site].highlighter when 'pygments' - render_pygments(code) + render_pygments(code, is_safe) when 'rouge' render_rouge(code) else @@ -57,8 +59,17 @@ eos prefix + rendered_output + suffix end - def render_pygments(code) + def render_pygments(code, is_safe) 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' highlighted_code = Pygments.highlight(code, :lexer => @lang, :options => @options)