Rename the pygments option to highlighter
Rename the pygments configuration option to highlighter to allow different highlighters in the future. For now, the allowed values are `pygments` and `null`. It's now more straightforward to plug another syntax highlighter.
This commit is contained in:
parent
903cce2745
commit
92064134d6
|
@ -1,6 +1,7 @@
|
||||||
## HEAD
|
## HEAD
|
||||||
|
|
||||||
### Major Enhancements
|
### Major Enhancements
|
||||||
|
* Rename the `pygments` option to `highlighter`
|
||||||
* Add gem-based plugin whitelist to safe mode (#1657)
|
* Add gem-based plugin whitelist to safe mode (#1657)
|
||||||
* Replace the commander command line parser with a more robust
|
* Replace the commander command line parser with a more robust
|
||||||
solution for our needs called `mercenary` (#1706)
|
solution for our needs called `mercenary` (#1706)
|
||||||
|
|
|
@ -24,12 +24,12 @@ module Jekyll
|
||||||
'limit_posts' => 0,
|
'limit_posts' => 0,
|
||||||
'lsi' => false,
|
'lsi' => false,
|
||||||
'future' => true, # remove and make true just default
|
'future' => true, # remove and make true just default
|
||||||
'pygments' => true,
|
|
||||||
|
|
||||||
'relative_permalinks' => true, # backwards-compatibility with < 1.0
|
'relative_permalinks' => true, # backwards-compatibility with < 1.0
|
||||||
# will be set to false once 2.0 hits
|
# will be set to false once 2.0 hits
|
||||||
|
|
||||||
'markdown' => 'maruku',
|
'markdown' => 'maruku',
|
||||||
|
'highlighter' => 'pygments',
|
||||||
'permalink' => 'date',
|
'permalink' => 'date',
|
||||||
'baseurl' => '/',
|
'baseurl' => '/',
|
||||||
'include' => ['.htaccess'],
|
'include' => ['.htaccess'],
|
||||||
|
@ -209,6 +209,13 @@ module Jekyll
|
||||||
config.delete('server_port')
|
config.delete('server_port')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if config.has_key? 'pygments'
|
||||||
|
Jekyll.logger.warn "Deprecation:", "The 'pygments' configuration option" +
|
||||||
|
" has been renamed to 'highlighter'. Please update your" +
|
||||||
|
" config file accordingly. The allowed values are 'rouge"+
|
||||||
|
"'pygments' or null"
|
||||||
|
end
|
||||||
|
|
||||||
%w[include exclude].each do |option|
|
%w[include exclude].each do |option|
|
||||||
if config.fetch(option, []).is_a?(String)
|
if config.fetch(option, []).is_a?(String)
|
||||||
Jekyll.logger.warn "Deprecation:", "The '#{option}' configuration option" +
|
Jekyll.logger.warn "Deprecation:", "The '#{option}' configuration option" +
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class Converter < Plugin
|
class Converter < Plugin
|
||||||
# Public: Get or set the pygments prefix. When an argument is specified,
|
# Public: Get or set the highlighter prefix. When an argument is specified,
|
||||||
# the prefix will be set. If no argument is specified, the current prefix
|
# the prefix will be set. If no argument is specified, the current prefix
|
||||||
# will be returned.
|
# will be returned.
|
||||||
#
|
#
|
||||||
# pygments_prefix - The String prefix (default: nil).
|
# highlighter_prefix - The String prefix (default: nil).
|
||||||
#
|
#
|
||||||
# Returns the String prefix.
|
# Returns the String prefix.
|
||||||
def self.pygments_prefix(pygments_prefix = nil)
|
def self.highlighter_prefix(highlighter_prefix = nil)
|
||||||
@pygments_prefix = pygments_prefix if pygments_prefix
|
@highlighter_prefix = highlighter_prefix if highlighter_prefix
|
||||||
@pygments_prefix
|
@highlighter_prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Get or set the pygments suffix. When an argument is specified,
|
# Public: Get or set the highlighter suffix. When an argument is specified,
|
||||||
# the suffix will be set. If no argument is specified, the current suffix
|
# the suffix will be set. If no argument is specified, the current suffix
|
||||||
# will be returned.
|
# will be returned.
|
||||||
#
|
#
|
||||||
# pygments_suffix - The String suffix (default: nil).
|
# highlighter_suffix - The String suffix (default: nil).
|
||||||
#
|
#
|
||||||
# Returns the String suffix.
|
# Returns the String suffix.
|
||||||
def self.pygments_suffix(pygments_suffix = nil)
|
def self.highlighter_suffix(highlighter_suffix = nil)
|
||||||
@pygments_suffix = pygments_suffix if pygments_suffix
|
@highlighter_suffix = highlighter_suffix if highlighter_suffix
|
||||||
@pygments_suffix
|
@highlighter_suffix
|
||||||
end
|
end
|
||||||
|
|
||||||
# Initialize the converter.
|
# Initialize the converter.
|
||||||
|
@ -31,18 +31,18 @@ module Jekyll
|
||||||
@config = config
|
@config = config
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the pygments prefix.
|
# Get the highlighter prefix.
|
||||||
#
|
#
|
||||||
# Returns the String prefix.
|
# Returns the String prefix.
|
||||||
def pygments_prefix
|
def highlighter_prefix
|
||||||
self.class.pygments_prefix
|
self.class.highlighter_prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the pygments suffix.
|
# Get the highlighter suffix.
|
||||||
#
|
#
|
||||||
# Returns the String suffix.
|
# Returns the String suffix.
|
||||||
def pygments_suffix
|
def highlighter_suffix
|
||||||
self.class.pygments_suffix
|
self.class.highlighter_suffix
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,8 +3,8 @@ module Jekyll
|
||||||
class Markdown < Converter
|
class Markdown < Converter
|
||||||
safe true
|
safe true
|
||||||
|
|
||||||
pygments_prefix "\n"
|
highlighter_prefix "\n"
|
||||||
pygments_suffix "\n"
|
highlighter_suffix "\n"
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
return if @setup
|
return if @setup
|
||||||
|
|
|
@ -43,7 +43,8 @@ module Jekyll
|
||||||
@redcarpet_extensions = {}
|
@redcarpet_extensions = {}
|
||||||
@config['redcarpet']['extensions'].each { |e| @redcarpet_extensions[e.to_sym] = true }
|
@config['redcarpet']['extensions'].each { |e| @redcarpet_extensions[e.to_sym] = true }
|
||||||
|
|
||||||
@renderer ||= if @config['pygments']
|
@renderer ||= case @config['highlighter']
|
||||||
|
when 'pygments'
|
||||||
Class.new(Redcarpet::Render::HTML) do
|
Class.new(Redcarpet::Render::HTML) do
|
||||||
include WithPygments
|
include WithPygments
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,8 +3,8 @@ module Jekyll
|
||||||
class Textile < Converter
|
class Textile < Converter
|
||||||
safe true
|
safe true
|
||||||
|
|
||||||
pygments_prefix '<notextile>'
|
highlighter_prefix '<notextile>'
|
||||||
pygments_suffix '</notextile>'
|
highlighter_suffix '</notextile>'
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
return if @setup
|
return if @setup
|
||||||
|
|
|
@ -144,8 +144,8 @@ module Jekyll
|
||||||
info = { :filters => [Jekyll::Filters], :registers => { :site => self.site, :page => payload['page'] } }
|
info = { :filters => [Jekyll::Filters], :registers => { :site => self.site, :page => payload['page'] } }
|
||||||
|
|
||||||
# render and transform content (this becomes the final content of the object)
|
# render and transform content (this becomes the final content of the object)
|
||||||
payload["pygments_prefix"] = converter.pygments_prefix
|
payload["highlighter_prefix"] = converter.highlighter_prefix
|
||||||
payload["pygments_suffix"] = converter.pygments_suffix
|
payload["highlighter_suffix"] = converter.highlighter_suffix
|
||||||
|
|
||||||
self.content = self.render_liquid(self.content,
|
self.content = self.render_liquid(self.content,
|
||||||
payload,
|
payload,
|
||||||
|
|
|
@ -9,8 +9,7 @@ module Jekyll
|
||||||
arg_is_present? args, "--auto", "The switch '--auto' has been replaced with '--watch'."
|
arg_is_present? args, "--auto", "The switch '--auto' has been replaced with '--watch'."
|
||||||
arg_is_present? args, "--no-auto", "To disable auto-replication, simply leave off \
|
arg_is_present? args, "--no-auto", "To disable auto-replication, simply leave off \
|
||||||
the '--watch' switch."
|
the '--watch' switch."
|
||||||
arg_is_present? args, "--pygments", "The 'pygments' setting can only be set in \
|
arg_is_present? args, "--pygments", "The 'pygments' setting has been removed"
|
||||||
your config files."
|
|
||||||
arg_is_present? args, "--paginate", "The 'paginate' setting can only be set in your \
|
arg_is_present? args, "--paginate", "The 'paginate' setting can only be set in your \
|
||||||
config files."
|
config files."
|
||||||
arg_is_present? args, "--url", "The 'url' setting can only be set in your config files."
|
arg_is_present? args, "--url", "The 'url' setting can only be set in your config files."
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class Site
|
class Site
|
||||||
attr_accessor :config, :layouts, :posts, :pages, :static_files,
|
attr_accessor :config, :layouts, :posts, :pages, :static_files,
|
||||||
:categories, :exclude, :include, :source, :dest, :lsi, :pygments,
|
:categories, :exclude, :include, :source, :dest, :lsi, :highlighter,
|
||||||
:permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts,
|
:permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts,
|
||||||
:show_drafts, :keep_files, :baseurl, :data, :file_read_opts, :gems
|
:show_drafts, :keep_files, :baseurl, :data, :file_read_opts, :gems
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ module Jekyll
|
||||||
def initialize(config)
|
def initialize(config)
|
||||||
self.config = config.clone
|
self.config = config.clone
|
||||||
|
|
||||||
%w[safe lsi pygments baseurl exclude include future show_drafts limit_posts keep_files gems].each do |opt|
|
%w[safe lsi highlighter baseurl exclude include future show_drafts limit_posts keep_files gems].each do |opt|
|
||||||
self.send("#{opt}=", config[opt])
|
self.send("#{opt}=", config[opt])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,8 @@ eos
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
if context.registers[:site].pygments
|
case context.registers[:site].highlighter
|
||||||
|
when 'pygments'
|
||||||
render_pygments(context, super)
|
render_pygments(context, super)
|
||||||
else
|
else
|
||||||
render_codehighlighter(context, super)
|
render_codehighlighter(context, super)
|
||||||
|
@ -58,9 +59,10 @@ eos
|
||||||
@lang
|
@lang
|
||||||
)
|
)
|
||||||
|
|
||||||
output = context["pygments_prefix"] + output if context["pygments_prefix"]
|
output = context["highlighter_prefix"] + output if context["highlighter_prefix"]
|
||||||
output = output + context["pygments_suffix"] if context["pygments_suffix"]
|
output << context["highlighter_suffix"] if context["highlighter_suffix"]
|
||||||
output
|
|
||||||
|
return output
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_codehighlighter(context, code)
|
def render_codehighlighter(context, code)
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
name: Your New Jekyll Site
|
name: Your New Jekyll Site
|
||||||
markdown: redcarpet
|
markdown: redcarpet
|
||||||
pygments: true
|
highlighter: pygments
|
||||||
|
|
|
@ -28,7 +28,7 @@ class TestRedcarpet < Test::Unit::TestCase
|
||||||
|
|
||||||
context "with pygments enabled" do
|
context "with pygments enabled" do
|
||||||
setup do
|
setup do
|
||||||
@markdown = Converters::Markdown.new @config.merge({ 'pygments' => true })
|
@markdown = Converters::Markdown.new @config.merge({ 'highlighter' => 'pygments' })
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render fenced code blocks with syntax highlighting" do
|
should "render fenced code blocks with syntax highlighting" do
|
||||||
|
@ -42,9 +42,9 @@ puts "Hello world"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with pygments disabled" do
|
context "without any highlighter" do
|
||||||
setup do
|
setup do
|
||||||
@markdown = Converters::Markdown.new @config.merge({ 'pygments' => false })
|
@markdown = Converters::Markdown.new @config.merge({ 'highlighter' => nil })
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render fenced code blocks without syntax highlighting" do
|
should "render fenced code blocks without syntax highlighting" do
|
||||||
|
|
|
@ -6,7 +6,7 @@ class TestTags < Test::Unit::TestCase
|
||||||
|
|
||||||
def create_post(content, override = {}, converter_class = Jekyll::Converters::Markdown)
|
def create_post(content, override = {}, converter_class = Jekyll::Converters::Markdown)
|
||||||
stub(Jekyll).configuration do
|
stub(Jekyll).configuration do
|
||||||
Jekyll::Configuration::DEFAULTS.deep_merge({'pygments' => true}).deep_merge(override)
|
Jekyll::Configuration::DEFAULTS.deep_merge({'highlighter' => 'pygments'}).deep_merge(override)
|
||||||
end
|
end
|
||||||
site = Site.new(Jekyll.configuration)
|
site = Site.new(Jekyll.configuration)
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ class TestTags < Test::Unit::TestCase
|
||||||
|
|
||||||
info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
|
info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
|
||||||
@converter = site.converters.find { |c| c.class == converter_class }
|
@converter = site.converters.find { |c| c.class == converter_class }
|
||||||
payload = { "pygments_prefix" => @converter.pygments_prefix,
|
payload = { "highlighter_prefix" => @converter.highlighter_prefix,
|
||||||
"pygments_suffix" => @converter.pygments_suffix }
|
"highlighter_suffix" => @converter.highlighter_suffix }
|
||||||
|
|
||||||
@result = Liquid::Template.parse(content).render!(payload, info)
|
@result = Liquid::Template.parse(content).render!(payload, info)
|
||||||
@result = @converter.convert(@result)
|
@result = @converter.convert(@result)
|
||||||
|
|
Loading…
Reference in New Issue