jekyll 3.9.3 → 4.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +511 -89
  3. data/LICENSE +1 -1
  4. data/README.markdown +48 -27
  5. data/lib/blank_template/_config.yml +3 -0
  6. data/lib/blank_template/_layouts/default.html +12 -0
  7. data/lib/blank_template/_sass/base.scss +9 -0
  8. data/lib/blank_template/assets/css/main.scss +4 -0
  9. data/lib/blank_template/index.md +8 -0
  10. data/lib/jekyll/cache.rb +186 -0
  11. data/lib/jekyll/cleaner.rb +8 -7
  12. data/lib/jekyll/collection.rb +84 -11
  13. data/lib/jekyll/command.rb +33 -6
  14. data/lib/jekyll/commands/build.rb +8 -28
  15. data/lib/jekyll/commands/clean.rb +3 -2
  16. data/lib/jekyll/commands/doctor.rb +46 -35
  17. data/lib/jekyll/commands/help.rb +1 -1
  18. data/lib/jekyll/commands/new.rb +44 -50
  19. data/lib/jekyll/commands/new_theme.rb +27 -28
  20. data/lib/jekyll/commands/serve/live_reload_reactor.rb +9 -16
  21. data/lib/jekyll/commands/serve/servlet.rb +21 -22
  22. data/lib/jekyll/commands/serve/websockets.rb +1 -1
  23. data/lib/jekyll/commands/serve.rb +75 -97
  24. data/lib/jekyll/configuration.rb +66 -158
  25. data/lib/jekyll/converters/identity.rb +18 -0
  26. data/lib/jekyll/converters/markdown/kramdown_parser.rb +83 -33
  27. data/lib/jekyll/converters/markdown.rb +49 -40
  28. data/lib/jekyll/converters/smartypants.rb +34 -14
  29. data/lib/jekyll/convertible.rb +36 -34
  30. data/lib/jekyll/deprecator.rb +2 -4
  31. data/lib/jekyll/document.rb +107 -72
  32. data/lib/jekyll/drops/collection_drop.rb +3 -4
  33. data/lib/jekyll/drops/document_drop.rb +9 -3
  34. data/lib/jekyll/drops/drop.rb +115 -33
  35. data/lib/jekyll/drops/excerpt_drop.rb +8 -0
  36. data/lib/jekyll/drops/site_drop.rb +9 -8
  37. data/lib/jekyll/drops/static_file_drop.rb +4 -4
  38. data/lib/jekyll/drops/theme_drop.rb +39 -0
  39. data/lib/jekyll/drops/unified_payload_drop.rb +7 -2
  40. data/lib/jekyll/drops/url_drop.rb +55 -3
  41. data/lib/jekyll/entry_filter.rb +42 -51
  42. data/lib/jekyll/excerpt.rb +48 -38
  43. data/lib/jekyll/external.rb +20 -19
  44. data/lib/jekyll/filters/date_filters.rb +6 -3
  45. data/lib/jekyll/filters/grouping_filters.rb +1 -2
  46. data/lib/jekyll/filters/url_filters.rb +50 -15
  47. data/lib/jekyll/filters.rb +211 -50
  48. data/lib/jekyll/frontmatter_defaults.rb +45 -36
  49. data/lib/jekyll/hooks.rb +26 -26
  50. data/lib/jekyll/inclusion.rb +32 -0
  51. data/lib/jekyll/layout.rb +12 -19
  52. data/lib/jekyll/liquid_extensions.rb +0 -2
  53. data/lib/jekyll/liquid_renderer/file.rb +24 -3
  54. data/lib/jekyll/liquid_renderer/table.rb +26 -77
  55. data/lib/jekyll/liquid_renderer.rb +31 -16
  56. data/lib/jekyll/log_adapter.rb +5 -1
  57. data/lib/jekyll/page.rb +51 -23
  58. data/lib/jekyll/page_excerpt.rb +25 -0
  59. data/lib/jekyll/page_without_a_file.rb +0 -4
  60. data/lib/jekyll/path_manager.rb +74 -0
  61. data/lib/jekyll/plugin.rb +5 -11
  62. data/lib/jekyll/plugin_manager.rb +15 -5
  63. data/lib/jekyll/profiler.rb +51 -0
  64. data/lib/jekyll/reader.rb +65 -10
  65. data/lib/jekyll/readers/collection_reader.rb +1 -0
  66. data/lib/jekyll/readers/data_reader.rb +48 -10
  67. data/lib/jekyll/readers/layout_reader.rb +3 -12
  68. data/lib/jekyll/readers/page_reader.rb +5 -5
  69. data/lib/jekyll/readers/post_reader.rb +32 -19
  70. data/lib/jekyll/readers/static_file_reader.rb +4 -4
  71. data/lib/jekyll/readers/theme_assets_reader.rb +8 -5
  72. data/lib/jekyll/regenerator.rb +4 -12
  73. data/lib/jekyll/related_posts.rb +1 -1
  74. data/lib/jekyll/renderer.rb +34 -49
  75. data/lib/jekyll/site.rb +151 -58
  76. data/lib/jekyll/static_file.rb +64 -28
  77. data/lib/jekyll/stevenson.rb +4 -8
  78. data/lib/jekyll/tags/highlight.rb +44 -57
  79. data/lib/jekyll/tags/include.rb +114 -80
  80. data/lib/jekyll/tags/link.rb +12 -7
  81. data/lib/jekyll/tags/post_url.rb +33 -30
  82. data/lib/jekyll/theme.rb +20 -18
  83. data/lib/jekyll/theme_builder.rb +91 -89
  84. data/lib/jekyll/url.rb +18 -10
  85. data/lib/jekyll/utils/ansi.rb +2 -2
  86. data/lib/jekyll/utils/exec.rb +0 -1
  87. data/lib/jekyll/utils/internet.rb +2 -4
  88. data/lib/jekyll/utils/platforms.rb +37 -52
  89. data/lib/jekyll/utils/thread_event.rb +1 -5
  90. data/lib/jekyll/utils.rb +29 -28
  91. data/lib/jekyll/version.rb +1 -1
  92. data/lib/jekyll.rb +9 -14
  93. data/lib/site_template/.gitignore +2 -0
  94. data/lib/site_template/404.html +2 -1
  95. data/lib/site_template/_config.yml +17 -5
  96. data/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb +5 -1
  97. data/lib/theme_template/README.md.erb +1 -3
  98. data/lib/theme_template/gitignore.erb +1 -0
  99. data/lib/theme_template/theme.gemspec.erb +1 -4
  100. data/rubocop/jekyll/assert_equal_literal_actual.rb +150 -0
  101. data/rubocop/jekyll/no_p_allowed.rb +5 -6
  102. data/rubocop/jekyll/no_puts_allowed.rb +5 -6
  103. metadata +149 -37
  104. data/lib/jekyll/converters/markdown/rdiscount_parser.rb +0 -37
  105. data/lib/jekyll/converters/markdown/redcarpet_parser.rb +0 -112
  106. data/lib/jekyll/utils/rouge.rb +0 -22
  107. /data/lib/site_template/{about.md → about.markdown} +0 -0
  108. /data/lib/site_template/{index.md → index.markdown} +0 -0
@@ -4,11 +4,12 @@ module Jekyll
4
4
  class Configuration < Hash
5
5
  # Default options. Overridden by values in _config.yml.
6
6
  # Strings rather than symbols are used for compatibility with YAML.
7
- DEFAULTS = Configuration[{
7
+ DEFAULTS = {
8
8
  # Where things are
9
9
  "source" => Dir.pwd,
10
10
  "destination" => File.join(Dir.pwd, "_site"),
11
11
  "collections_dir" => "",
12
+ "cache_dir" => ".jekyll-cache",
12
13
  "plugins_dir" => "_plugins",
13
14
  "layouts_dir" => "_layouts",
14
15
  "data_dir" => "_data",
@@ -18,10 +19,7 @@ module Jekyll
18
19
  # Handling Reading
19
20
  "safe" => false,
20
21
  "include" => [".htaccess"],
21
- "exclude" => %w(
22
- Gemfile Gemfile.lock node_modules vendor/bundle/ vendor/cache/ vendor/gems/
23
- vendor/ruby/
24
- ),
22
+ "exclude" => [],
25
23
  "keep_files" => [".git", ".svn"],
26
24
  "encoding" => "utf-8",
27
25
  "markdown_ext" => "markdown,mkdown,mkdn,mkd,md",
@@ -66,17 +64,9 @@ module Jekyll
66
64
  "strict_variables" => false,
67
65
  },
68
66
 
69
- "rdiscount" => {
70
- "extensions" => [],
71
- },
72
-
73
- "redcarpet" => {
74
- "extensions" => [],
75
- },
76
-
77
67
  "kramdown" => {
78
68
  "auto_ids" => true,
79
- "toc_levels" => "1..6",
69
+ "toc_levels" => (1..6).to_a,
80
70
  "entity_output" => "as_char",
81
71
  "smart_quotes" => "lsquo,rsquo,ldquo,rdquo",
82
72
  "input" => "GFM",
@@ -85,22 +75,18 @@ module Jekyll
85
75
  "footnote_nr" => 1,
86
76
  "show_warnings" => false,
87
77
  },
88
- }.map { |k, v| [k, v.freeze] }].freeze
78
+ }.each_with_object(Configuration.new) { |(k, v), hsh| hsh[k] = v.freeze }.freeze
89
79
 
90
80
  class << self
91
81
  # Static: Produce a Configuration ready for use in a Site.
92
- # It takes the input, fills in the defaults where values do not
93
- # exist, and patches common issues including migrating options for
94
- # backwards compatiblity. Except where a key or value is being fixed,
95
- # the user configuration will override the defaults.
82
+ # It takes the input, fills in the defaults where values do not exist.
96
83
  #
97
84
  # user_config - a Hash or Configuration of overrides.
98
85
  #
99
- # Returns a Configuration filled with defaults and fixed for common
100
- # problems and backwards-compatibility.
86
+ # Returns a Configuration filled with defaults.
101
87
  def from(user_config)
102
88
  Utils.deep_merge_hashes(DEFAULTS, Configuration[user_config].stringify_keys)
103
- .add_default_collections
89
+ .add_default_collections.add_default_excludes
104
90
  end
105
91
  end
106
92
 
@@ -108,7 +94,7 @@ module Jekyll
108
94
  #
109
95
  # Return a copy of the hash where all its keys are strings
110
96
  def stringify_keys
111
- reduce({}) { |hsh, (k, v)| hsh.merge(k.to_s => v) }
97
+ each_with_object({}) { |(k, v), hsh| hsh[k.to_s] = v }
112
98
  end
113
99
 
114
100
  def get_config_value_with_override(config_key, override)
@@ -142,8 +128,8 @@ module Jekyll
142
128
  when %r!\.ya?ml!i
143
129
  SafeYAML.load_file(filename) || {}
144
130
  else
145
- raise ArgumentError, "No parser for '#{filename}' is available.
146
- Use a .y(a)ml or .toml file instead."
131
+ raise ArgumentError,
132
+ "No parser for '#{filename}' is available. Use a .y(a)ml or .toml file instead."
147
133
  end
148
134
  end
149
135
 
@@ -162,7 +148,7 @@ module Jekyll
162
148
  # Get configuration from <source>/_config.yml or <source>/<config_file>
163
149
  config_files = override["config"]
164
150
  if config_files.to_s.empty?
165
- default = %w(yml yaml).find(-> { "yml" }) do |ext|
151
+ default = %w(yml yaml toml).find(-> { "yml" }) do |ext|
166
152
  File.exist?(Jekyll.sanitized_path(source(override), "_config.#{ext}"))
167
153
  end
168
154
  config_files = Jekyll.sanitized_path(source(override), "_config.#{default}")
@@ -177,8 +163,13 @@ module Jekyll
177
163
  #
178
164
  # Returns this configuration, overridden by the values in the file
179
165
  def read_config_file(file)
166
+ file = File.expand_path(file)
180
167
  next_config = safe_load_file(file)
181
- check_config_is_hash!(next_config, file)
168
+
169
+ unless next_config.is_a?(Hash)
170
+ raise ArgumentError, "Configuration file: (INVALID) #{file}".yellow
171
+ end
172
+
182
173
  Jekyll.logger.info "Configuration file:", file
183
174
  next_config
184
175
  rescue SystemCallError
@@ -186,8 +177,7 @@ module Jekyll
186
177
  Jekyll.logger.warn "Configuration file:", "none"
187
178
  {}
188
179
  else
189
- Jekyll.logger.error "Fatal:", "The configuration file '#{file}'
190
- could not be found."
180
+ Jekyll.logger.error "Fatal:", "The configuration file '#{file}' could not be found."
191
181
  raise LoadError, "The Configuration file '#{file}' could not be found."
192
182
  end
193
183
  end
@@ -204,16 +194,16 @@ module Jekyll
204
194
  begin
205
195
  files.each do |config_file|
206
196
  next if config_file.nil? || config_file.empty?
197
+
207
198
  new_config = read_config_file(config_file)
208
199
  configuration = Utils.deep_merge_hashes(configuration, new_config)
209
200
  end
210
- rescue ArgumentError => err
211
- Jekyll.logger.warn "WARNING:", "Error reading configuration. " \
212
- "Using defaults (and options)."
213
- warn err
201
+ rescue ArgumentError => e
202
+ Jekyll.logger.warn "WARNING:", "Error reading configuration. Using defaults (and options)."
203
+ warn e
214
204
  end
215
205
 
216
- configuration.backwards_compatibilize.add_default_collections
206
+ configuration.validate.add_default_collections
217
207
  end
218
208
 
219
209
  # Public: Split a CSV string into an array containing its values
@@ -225,35 +215,18 @@ module Jekyll
225
215
  csv.split(",").map(&:strip)
226
216
  end
227
217
 
228
- # Public: Ensure the proper options are set in the configuration to allow for
229
- # backwards-compatibility with Jekyll pre-1.0
218
+ # Public: Ensure the proper options are set in the configuration
230
219
  #
231
- # Returns the backwards-compatible configuration
232
- def backwards_compatibilize
220
+ # Returns the configuration Hash
221
+ def validate
233
222
  config = clone
234
- # Provide backwards-compatibility
235
- check_auto(config)
236
- check_server(config)
237
- check_plugins(config)
238
223
 
239
- renamed_key "server_port", "port", config
240
- renamed_key "gems", "plugins", config
241
- renamed_key "layouts", "layouts_dir", config
242
- renamed_key "data_source", "data_dir", config
243
-
244
- check_pygments(config)
224
+ check_plugins(config)
245
225
  check_include_exclude(config)
246
- check_coderay(config)
247
- check_maruku(config)
248
226
 
249
227
  config
250
228
  end
251
229
 
252
- # DEPRECATED.
253
- def fix_common_issues
254
- self
255
- end
256
-
257
230
  def add_default_collections
258
231
  config = clone
259
232
 
@@ -262,7 +235,9 @@ module Jekyll
262
235
 
263
236
  # Ensure we have a hash.
264
237
  if config["collections"].is_a?(Array)
265
- config["collections"] = Hash[config["collections"].map { |c| [c, {}] }]
238
+ config["collections"] = config["collections"].each_with_object({}) do |collection, hash|
239
+ hash[collection] = {}
240
+ end
266
241
  end
267
242
 
268
243
  config["collections"] = Utils.deep_merge_hashes(
@@ -277,109 +252,44 @@ module Jekyll
277
252
  config
278
253
  end
279
254
 
280
- def renamed_key(old, new, config, _ = nil)
281
- if config.key?(old)
282
- Jekyll::Deprecator.deprecation_message "The '#{old}' configuration" \
283
- " option has been renamed to '#{new}'. Please update your config" \
284
- " file accordingly."
285
- config[new] = config.delete(old)
286
- end
287
- end
255
+ DEFAULT_EXCLUDES = %w(
256
+ .sass-cache .jekyll-cache
257
+ gemfiles Gemfile Gemfile.lock
258
+ node_modules
259
+ vendor/bundle/ vendor/cache/ vendor/gems/ vendor/ruby/
260
+ ).freeze
288
261
 
289
- private
290
- def style_to_permalink(permalink_style)
291
- case permalink_style.to_sym
292
- when :pretty
293
- "/:categories/:year/:month/:day/:title/"
294
- when :none
295
- "/:categories/:title:output_ext"
296
- when :date
297
- "/:categories/:year/:month/:day/:title:output_ext"
298
- when :ordinal
299
- "/:categories/:year/:y_day/:title:output_ext"
300
- else
301
- permalink_style.to_s
302
- end
303
- end
262
+ def add_default_excludes
263
+ config = clone
264
+ return config if config["exclude"].nil?
304
265
 
305
- # Private: Checks if a given config is a hash
306
- #
307
- # extracted_config - the value to check
308
- # file - the file from which the config was extracted
309
- #
310
- # Raises an ArgumentError if given config is not a hash
311
- private
312
- def check_config_is_hash!(extracted_config, file)
313
- unless extracted_config.is_a?(Hash)
314
- raise ArgumentError, "Configuration file: (INVALID) #{file}".yellow
315
- end
266
+ config["exclude"].concat(DEFAULT_EXCLUDES).uniq!
267
+ config
316
268
  end
317
269
 
318
270
  private
319
- def check_auto(config)
320
- if config.key?("auto") || config.key?("watch")
321
- Jekyll::Deprecator.deprecation_message "Auto-regeneration can no longer" \
322
- " be set from your configuration file(s). Use the" \
323
- " --[no-]watch/-w command-line option instead."
324
- config.delete("auto")
325
- config.delete("watch")
326
- end
327
- end
328
271
 
329
- private
330
- def check_server(config)
331
- if config.key?("server")
332
- Jekyll::Deprecator.deprecation_message "The 'server' configuration option" \
333
- " is no longer accepted. Use the 'jekyll serve'" \
334
- " subcommand to serve your site with WEBrick."
335
- config.delete("server")
336
- end
337
- end
272
+ STYLE_TO_PERMALINK = {
273
+ :none => "/:categories/:title:output_ext",
274
+ :date => "/:categories/:year/:month/:day/:title:output_ext",
275
+ :ordinal => "/:categories/:year/:y_day/:title:output_ext",
276
+ :pretty => "/:categories/:year/:month/:day/:title/",
277
+ :weekdate => "/:categories/:year/W:week/:short_day/:title:output_ext",
278
+ }.freeze
338
279
 
339
- private
340
- def check_pygments(config)
341
- if config.key?("pygments")
342
- Jekyll::Deprecator.deprecation_message "The 'pygments' configuration option" \
343
- " has been renamed to 'highlighter'. Please update your" \
344
- " config file accordingly. The allowed values are 'rouge', " \
345
- "'pygments' or null."
346
-
347
- config["highlighter"] = "pygments" if config["pygments"]
348
- config.delete("pygments")
349
- end
280
+ private_constant :STYLE_TO_PERMALINK
281
+
282
+ def style_to_permalink(permalink_style)
283
+ STYLE_TO_PERMALINK[permalink_style.to_sym] || permalink_style.to_s
350
284
  end
351
285
 
352
- private
353
286
  def check_include_exclude(config)
354
287
  %w(include exclude).each do |option|
355
- if config[option].is_a?(String)
356
- Jekyll::Deprecator.deprecation_message "The '#{option}' configuration option" \
357
- " must now be specified as an array, but you specified" \
358
- " a string. For now, we've treated the string you provided" \
359
- " as a list of comma-separated values."
360
- config[option] = csv_to_array(config[option])
361
- end
362
- config[option].map!(&:to_s) if config[option]
363
- end
364
- end
365
-
366
- private
367
- def check_coderay(config)
368
- if (config["kramdown"] || {}).key?("use_coderay")
369
- Jekyll::Deprecator.deprecation_message "Please change 'use_coderay'" \
370
- " to 'enable_coderay' in your configuration file."
371
- config["kramdown"]["use_coderay"] = config["kramdown"].delete("enable_coderay")
372
- end
373
- end
288
+ next unless config.key?(option)
289
+ next if config[option].is_a?(Array)
374
290
 
375
- private
376
- def check_maruku(config)
377
- if config.fetch("markdown", "kramdown").to_s.casecmp("maruku").zero?
378
- Jekyll.logger.abort_with "Error:", "You're using the 'maruku' " \
379
- "Markdown processor, which has been removed as of 3.0.0. " \
380
- "We recommend you switch to Kramdown. To do this, replace " \
381
- "`markdown: maruku` with `markdown: kramdown` in your " \
382
- "`_config.yml` file."
291
+ raise Jekyll::Errors::InvalidConfigurationError,
292
+ "'#{option}' should be set as an array, but was: #{config[option].inspect}."
383
293
  end
384
294
  end
385
295
 
@@ -388,18 +298,16 @@ module Jekyll
388
298
  # config - the config hash
389
299
  #
390
300
  # Raises a Jekyll::Errors::InvalidConfigurationError if the config `plugins`
391
- # is a string
392
- private
301
+ # is not an Array.
393
302
  def check_plugins(config)
394
- if config.key?("plugins") && config["plugins"].is_a?(String)
395
- Jekyll.logger.error "Configuration Error:", "You specified the" \
396
- " `plugins` config in your configuration file as a string, please" \
397
- " use an array instead. If you wanted to set the directory of your" \
398
- " plugins, use the config key `plugins_dir` instead."
399
- raise Jekyll::Errors::InvalidConfigurationError,
400
- "'plugins' should not be a string, but was: " \
401
- "#{config["plugins"].inspect}. Use 'plugins_dir' instead."
402
- end
303
+ return unless config.key?("plugins")
304
+ return if config["plugins"].is_a?(Array)
305
+
306
+ Jekyll.logger.error "'plugins' should be set as an array of gem-names, but was: " \
307
+ "#{config["plugins"].inspect}. Use 'plugins_dir' instead to set " \
308
+ "the directory for your non-gemified Ruby plugins."
309
+ raise Jekyll::Errors::InvalidConfigurationError,
310
+ "'plugins' should be set as an array, but was: #{config["plugins"].inspect}."
403
311
  end
404
312
  end
405
313
  end
@@ -2,19 +2,37 @@
2
2
 
3
3
  module Jekyll
4
4
  module Converters
5
+ # Identity converter. Returns same content as given.
6
+ # For more info on converters see https://jekyllrb.com/docs/plugins/converters/
5
7
  class Identity < Converter
6
8
  safe true
7
9
 
8
10
  priority :lowest
9
11
 
12
+ # Public: Does the given extension match this converter's list of acceptable extensions?
13
+ # Takes one argument: the file's extension (including the dot).
14
+ #
15
+ # _ext - The String extension to check (not relevant here)
16
+ #
17
+ # Returns true since it always matches.
10
18
  def matches(_ext)
11
19
  true
12
20
  end
13
21
 
22
+ # Public: The extension to be given to the output file (including the dot).
23
+ #
24
+ # ext - The String extension or original file.
25
+ #
26
+ # Returns The String output file extension.
14
27
  def output_ext(ext)
15
28
  ext
16
29
  end
17
30
 
31
+ # Logic to do the content conversion.
32
+ #
33
+ # content - String content of file (without front matter).
34
+ #
35
+ # Returns a String of the converted content.
18
36
  def convert(content)
19
37
  content
20
38
  end
@@ -1,4 +1,72 @@
1
- # Frozen-string-literal: true
1
+ # frozen_string_literal: true
2
+
3
+ module Kramdown
4
+ # A Kramdown::Document subclass meant to optimize memory usage from initializing
5
+ # a kramdown document for parsing.
6
+ #
7
+ # The optimization is by using the same options Hash (and its derivatives) for
8
+ # converting all Markdown documents in a Jekyll site.
9
+ class JekyllDocument < Document
10
+ class << self
11
+ attr_reader :options, :parser
12
+
13
+ # The implementation is basically the core logic in +Kramdown::Document#initialize+
14
+ #
15
+ # rubocop:disable Naming/MemoizedInstanceVariableName
16
+ def setup(options)
17
+ @cache ||= {}
18
+
19
+ # reset variables on a subsequent set up with a different options Hash
20
+ unless @cache[:id] == options.hash
21
+ @options = @parser = nil
22
+ @cache[:id] = options.hash
23
+ end
24
+
25
+ @options ||= Options.merge(options).freeze
26
+ @parser ||= begin
27
+ parser_name = (@options[:input] || "kramdown").to_s
28
+ parser_name = parser_name[0..0].upcase + parser_name[1..-1]
29
+ try_require("parser", parser_name)
30
+
31
+ if Parser.const_defined?(parser_name)
32
+ Parser.const_get(parser_name)
33
+ else
34
+ raise Kramdown::Error, "kramdown has no parser to handle the specified " \
35
+ "input format: #{@options[:input]}"
36
+ end
37
+ end
38
+ end
39
+ # rubocop:enable Naming/MemoizedInstanceVariableName
40
+
41
+ private
42
+
43
+ def try_require(type, name)
44
+ require "kramdown/#{type}/#{Utils.snake_case(name)}"
45
+ rescue LoadError
46
+ false
47
+ end
48
+ end
49
+
50
+ def initialize(source, options = {})
51
+ JekyllDocument.setup(options)
52
+
53
+ @options = JekyllDocument.options
54
+ @root, @warnings = JekyllDocument.parser.parse(source, @options)
55
+ end
56
+
57
+ # Use Kramdown::Converter::Html class to convert this document into HTML.
58
+ #
59
+ # The implementation is basically an optimized version of core logic in
60
+ # +Kramdown::Document#method_missing+ from kramdown-2.1.0.
61
+ def to_html
62
+ output, warnings = Kramdown::Converter::Html.convert(@root, @options)
63
+ @warnings.concat(warnings)
64
+ output
65
+ end
66
+ end
67
+ end
68
+
69
+ #
2
70
 
3
71
  module Jekyll
4
72
  module Converters
@@ -35,11 +103,10 @@ module Jekyll
35
103
  @config["syntax_highlighter_opts"]["guess_lang"] = @config["guess_lang"]
36
104
  @config["coderay"] ||= {} # XXX: Legacy.
37
105
  modernize_coderay_config
38
- make_accessible
39
106
  end
40
107
 
41
108
  def convert(content)
42
- document = Kramdown::Document.new(content, @config)
109
+ document = Kramdown::JekyllDocument.new(content, @config)
43
110
  html_output = document.to_html
44
111
  if @config["show_warnings"]
45
112
  document.warnings.each do |warning|
@@ -52,36 +119,24 @@ module Jekyll
52
119
  private
53
120
 
54
121
  def load_dependencies
55
- return if Kramdown::VERSION.to_i < 2
56
- if @config["input"] == "GFM"
57
- Jekyll::External.require_with_graceful_fail("kramdown-parser-gfm")
58
- end
122
+ require "kramdown-parser-gfm" if @config["input"] == "GFM"
59
123
 
60
124
  if highlighter == "coderay"
61
125
  Jekyll::External.require_with_graceful_fail("kramdown-syntax-coderay")
62
126
  end
63
127
 
64
- # `mathjax` emgine is bundled within kramdown-2.x and will be handled by
128
+ # `mathjax` engine is bundled within kramdown-2.x and will be handled by
65
129
  # kramdown itself.
66
130
  if (math_engine = @config["math_engine"]) && math_engine != "mathjax"
67
131
  Jekyll::External.require_with_graceful_fail("kramdown-math-#{math_engine}")
68
132
  end
69
133
  end
70
134
 
71
- def make_accessible(hash = @config)
72
- hash.keys.each do |key|
73
- hash[key.to_sym] = hash[key]
74
- make_accessible(hash[key]) if hash[key].is_a?(Hash)
75
- end
76
- end
77
-
78
- # config[kramdown][syntax_higlighter] >
135
+ # config[kramdown][syntax_highlighter] >
79
136
  # config[kramdown][enable_coderay] >
80
137
  # config[highlighter]
81
138
  # Where `enable_coderay` is now deprecated because Kramdown
82
139
  # supports Rouge now too.
83
-
84
- private
85
140
  def highlighter
86
141
  return @highlighter if @highlighter
87
142
 
@@ -91,24 +146,21 @@ module Jekyll
91
146
  ]
92
147
  end
93
148
 
94
- @highlighter = begin
95
- if @config.key?("enable_coderay") && @config["enable_coderay"]
96
- Jekyll::Deprecator.deprecation_message(
97
- "You are using 'enable_coderay', " \
98
- "use syntax_highlighter: coderay in your configuration file."
99
- )
149
+ @highlighter = if @config.key?("enable_coderay") && @config["enable_coderay"]
150
+ Jekyll::Deprecator.deprecation_message(
151
+ "You are using 'enable_coderay', " \
152
+ "use syntax_highlighter: coderay in your configuration file."
153
+ )
100
154
 
101
- "coderay"
102
- else
103
- @main_fallback_highlighter
104
- end
105
- end
155
+ "coderay"
156
+ else
157
+ @main_fallback_highlighter
158
+ end
106
159
  end
107
160
 
108
- private
109
161
  def strip_coderay_prefix(hash)
110
162
  hash.each_with_object({}) do |(key, val), hsh|
111
- cleaned_key = key.to_s.gsub(%r!\Acoderay_!, "")
163
+ cleaned_key = key.to_s.delete_prefix("coderay_")
112
164
 
113
165
  if key != cleaned_key
114
166
  Jekyll::Deprecator.deprecation_message(
@@ -123,8 +175,6 @@ module Jekyll
123
175
  # If our highlighter is CodeRay we go in to merge the CodeRay defaults
124
176
  # with your "coderay" key if it's there, deprecating it in the
125
177
  # process of you using it.
126
-
127
- private
128
178
  def modernize_coderay_config
129
179
  unless @config["coderay"].empty?
130
180
  Jekyll::Deprecator.deprecation_message(