jekyll 4.2.1 → 4.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +474 -350
- data/LICENSE +21 -21
- data/README.markdown +83 -86
- data/exe/jekyll +57 -57
- data/lib/blank_template/_config.yml +3 -3
- data/lib/blank_template/_layouts/default.html +12 -12
- data/lib/blank_template/_sass/{main.scss → base.scss} +9 -9
- data/lib/blank_template/assets/css/main.scss +4 -4
- data/lib/blank_template/index.md +8 -8
- data/lib/jekyll/cache.rb +186 -190
- data/lib/jekyll/cleaner.rb +111 -111
- data/lib/jekyll/collection.rb +310 -309
- data/lib/jekyll/command.rb +105 -105
- data/lib/jekyll/commands/build.rb +82 -93
- data/lib/jekyll/commands/clean.rb +44 -45
- data/lib/jekyll/commands/doctor.rb +177 -177
- data/lib/jekyll/commands/help.rb +34 -34
- data/lib/jekyll/commands/new.rb +168 -169
- data/lib/jekyll/commands/new_theme.rb +39 -40
- data/lib/jekyll/commands/serve/live_reload_reactor.rb +119 -122
- data/lib/jekyll/commands/serve/livereload_assets/livereload.js +1183 -1183
- data/lib/jekyll/commands/serve/mime_types_charset.json +71 -0
- data/lib/jekyll/commands/serve/servlet.rb +206 -202
- data/lib/jekyll/commands/serve/websockets.rb +81 -81
- data/lib/jekyll/commands/serve.rb +367 -362
- data/lib/jekyll/configuration.rb +313 -313
- data/lib/jekyll/converter.rb +54 -54
- data/lib/jekyll/converters/identity.rb +41 -41
- data/lib/jekyll/converters/markdown/kramdown_parser.rb +197 -199
- data/lib/jekyll/converters/markdown.rb +113 -113
- data/lib/jekyll/converters/smartypants.rb +70 -70
- data/lib/jekyll/convertible.rb +257 -257
- data/lib/jekyll/deprecator.rb +50 -50
- data/lib/jekyll/document.rb +543 -544
- data/lib/jekyll/drops/collection_drop.rb +20 -20
- data/lib/jekyll/drops/document_drop.rb +74 -70
- data/lib/jekyll/drops/drop.rb +293 -293
- data/lib/jekyll/drops/excerpt_drop.rb +23 -19
- data/lib/jekyll/drops/jekyll_drop.rb +32 -32
- data/lib/jekyll/drops/site_drop.rb +66 -66
- data/lib/jekyll/drops/static_file_drop.rb +14 -14
- data/lib/jekyll/drops/theme_drop.rb +36 -0
- data/lib/jekyll/drops/unified_payload_drop.rb +30 -26
- data/lib/jekyll/drops/url_drop.rb +140 -140
- data/lib/jekyll/entry_filter.rb +117 -121
- data/lib/jekyll/errors.rb +20 -20
- data/lib/jekyll/excerpt.rb +200 -201
- data/lib/jekyll/external.rb +75 -79
- data/lib/jekyll/filters/date_filters.rb +110 -110
- data/lib/jekyll/filters/grouping_filters.rb +64 -64
- data/lib/jekyll/filters/url_filters.rb +98 -98
- data/lib/jekyll/filters.rb +532 -535
- data/lib/jekyll/frontmatter_defaults.rb +238 -240
- data/lib/jekyll/generator.rb +5 -5
- data/lib/jekyll/hooks.rb +107 -107
- data/lib/jekyll/inclusion.rb +32 -32
- data/lib/jekyll/layout.rb +55 -67
- data/lib/jekyll/liquid_extensions.rb +22 -22
- data/lib/jekyll/liquid_renderer/file.rb +77 -77
- data/lib/jekyll/liquid_renderer/table.rb +45 -55
- data/lib/jekyll/liquid_renderer.rb +80 -80
- data/lib/jekyll/log_adapter.rb +151 -151
- data/lib/jekyll/mime.types +939 -866
- data/lib/jekyll/page.rb +215 -217
- data/lib/jekyll/page_excerpt.rb +25 -25
- data/lib/jekyll/page_without_a_file.rb +14 -14
- data/lib/jekyll/path_manager.rb +74 -74
- data/lib/jekyll/plugin.rb +92 -92
- data/lib/jekyll/plugin_manager.rb +123 -115
- data/lib/jekyll/profiler.rb +51 -58
- data/lib/jekyll/publisher.rb +23 -23
- data/lib/jekyll/reader.rb +209 -192
- data/lib/jekyll/readers/collection_reader.rb +23 -23
- data/lib/jekyll/readers/data_reader.rb +113 -79
- data/lib/jekyll/readers/layout_reader.rb +62 -62
- data/lib/jekyll/readers/page_reader.rb +25 -25
- data/lib/jekyll/readers/post_reader.rb +85 -85
- data/lib/jekyll/readers/static_file_reader.rb +25 -25
- data/lib/jekyll/readers/theme_assets_reader.rb +52 -52
- data/lib/jekyll/regenerator.rb +195 -195
- data/lib/jekyll/related_posts.rb +52 -52
- data/lib/jekyll/renderer.rb +263 -265
- data/lib/jekyll/site.rb +576 -551
- data/lib/jekyll/static_file.rb +205 -208
- data/lib/jekyll/stevenson.rb +60 -60
- data/lib/jekyll/tags/highlight.rb +114 -110
- data/lib/jekyll/tags/include.rb +275 -275
- data/lib/jekyll/tags/link.rb +42 -42
- data/lib/jekyll/tags/post_url.rb +106 -106
- data/lib/jekyll/theme.rb +90 -86
- data/lib/jekyll/theme_builder.rb +121 -121
- data/lib/jekyll/url.rb +167 -167
- data/lib/jekyll/utils/ansi.rb +57 -57
- data/lib/jekyll/utils/exec.rb +26 -26
- data/lib/jekyll/utils/internet.rb +37 -37
- data/lib/jekyll/utils/platforms.rb +67 -67
- data/lib/jekyll/utils/thread_event.rb +31 -31
- data/lib/jekyll/utils/win_tz.rb +46 -75
- data/lib/jekyll/utils.rb +371 -367
- data/lib/jekyll/version.rb +5 -5
- data/lib/jekyll.rb +195 -195
- data/lib/site_template/.gitignore +5 -5
- data/lib/site_template/404.html +25 -25
- data/lib/site_template/_config.yml +55 -55
- data/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb +29 -29
- data/lib/site_template/about.markdown +18 -18
- data/lib/site_template/index.markdown +6 -6
- data/lib/theme_template/CODE_OF_CONDUCT.md.erb +74 -74
- data/lib/theme_template/Gemfile +4 -4
- data/lib/theme_template/LICENSE.txt.erb +21 -21
- data/lib/theme_template/README.md.erb +50 -52
- data/lib/theme_template/_layouts/default.html +1 -1
- data/lib/theme_template/_layouts/page.html +5 -5
- data/lib/theme_template/_layouts/post.html +5 -5
- data/lib/theme_template/example/_config.yml.erb +1 -1
- data/lib/theme_template/example/_post.md +12 -12
- data/lib/theme_template/example/index.html +14 -14
- data/lib/theme_template/example/style.scss +7 -7
- data/lib/theme_template/gitignore.erb +6 -6
- data/lib/theme_template/theme.gemspec.erb +16 -16
- data/rubocop/jekyll/assert_equal_literal_actual.rb +149 -149
- data/rubocop/jekyll/no_p_allowed.rb +23 -23
- data/rubocop/jekyll/no_puts_allowed.rb +23 -23
- data/rubocop/jekyll.rb +5 -5
- metadata +64 -18
data/lib/jekyll/converter.rb
CHANGED
@@ -1,54 +1,54 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
class Converter < Plugin
|
5
|
-
# Public: Get or set the highlighter prefix. When an argument is specified,
|
6
|
-
# the prefix will be set. If no argument is specified, the current prefix
|
7
|
-
# will be returned.
|
8
|
-
#
|
9
|
-
# highlighter_prefix - The String prefix (default: nil).
|
10
|
-
#
|
11
|
-
# Returns the String prefix.
|
12
|
-
def self.highlighter_prefix(highlighter_prefix = nil)
|
13
|
-
unless defined?(@highlighter_prefix) && highlighter_prefix.nil?
|
14
|
-
@highlighter_prefix = highlighter_prefix
|
15
|
-
end
|
16
|
-
@highlighter_prefix
|
17
|
-
end
|
18
|
-
|
19
|
-
# Public: Get or set the highlighter suffix. When an argument is specified,
|
20
|
-
# the suffix will be set. If no argument is specified, the current suffix
|
21
|
-
# will be returned.
|
22
|
-
#
|
23
|
-
# highlighter_suffix - The String suffix (default: nil).
|
24
|
-
#
|
25
|
-
# Returns the String suffix.
|
26
|
-
def self.highlighter_suffix(highlighter_suffix = nil)
|
27
|
-
unless defined?(@highlighter_suffix) && highlighter_suffix.nil?
|
28
|
-
@highlighter_suffix = highlighter_suffix
|
29
|
-
end
|
30
|
-
@highlighter_suffix
|
31
|
-
end
|
32
|
-
|
33
|
-
# Initialize the converter.
|
34
|
-
#
|
35
|
-
# Returns an initialized Converter.
|
36
|
-
def initialize(config = {})
|
37
|
-
@config = config
|
38
|
-
end
|
39
|
-
|
40
|
-
# Get the highlighter prefix.
|
41
|
-
#
|
42
|
-
# Returns the String prefix.
|
43
|
-
def highlighter_prefix
|
44
|
-
self.class.highlighter_prefix
|
45
|
-
end
|
46
|
-
|
47
|
-
# Get the highlighter suffix.
|
48
|
-
#
|
49
|
-
# Returns the String suffix.
|
50
|
-
def highlighter_suffix
|
51
|
-
self.class.highlighter_suffix
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Converter < Plugin
|
5
|
+
# Public: Get or set the highlighter prefix. When an argument is specified,
|
6
|
+
# the prefix will be set. If no argument is specified, the current prefix
|
7
|
+
# will be returned.
|
8
|
+
#
|
9
|
+
# highlighter_prefix - The String prefix (default: nil).
|
10
|
+
#
|
11
|
+
# Returns the String prefix.
|
12
|
+
def self.highlighter_prefix(highlighter_prefix = nil)
|
13
|
+
unless defined?(@highlighter_prefix) && highlighter_prefix.nil?
|
14
|
+
@highlighter_prefix = highlighter_prefix
|
15
|
+
end
|
16
|
+
@highlighter_prefix
|
17
|
+
end
|
18
|
+
|
19
|
+
# Public: Get or set the highlighter suffix. When an argument is specified,
|
20
|
+
# the suffix will be set. If no argument is specified, the current suffix
|
21
|
+
# will be returned.
|
22
|
+
#
|
23
|
+
# highlighter_suffix - The String suffix (default: nil).
|
24
|
+
#
|
25
|
+
# Returns the String suffix.
|
26
|
+
def self.highlighter_suffix(highlighter_suffix = nil)
|
27
|
+
unless defined?(@highlighter_suffix) && highlighter_suffix.nil?
|
28
|
+
@highlighter_suffix = highlighter_suffix
|
29
|
+
end
|
30
|
+
@highlighter_suffix
|
31
|
+
end
|
32
|
+
|
33
|
+
# Initialize the converter.
|
34
|
+
#
|
35
|
+
# Returns an initialized Converter.
|
36
|
+
def initialize(config = {})
|
37
|
+
@config = config
|
38
|
+
end
|
39
|
+
|
40
|
+
# Get the highlighter prefix.
|
41
|
+
#
|
42
|
+
# Returns the String prefix.
|
43
|
+
def highlighter_prefix
|
44
|
+
self.class.highlighter_prefix
|
45
|
+
end
|
46
|
+
|
47
|
+
# Get the highlighter suffix.
|
48
|
+
#
|
49
|
+
# Returns the String suffix.
|
50
|
+
def highlighter_suffix
|
51
|
+
self.class.highlighter_suffix
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,41 +1,41 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
module Converters
|
5
|
-
# Identity converter. Returns same content as given.
|
6
|
-
# For more info on converters see https://jekyllrb.com/docs/plugins/converters/
|
7
|
-
class Identity < Converter
|
8
|
-
safe true
|
9
|
-
|
10
|
-
priority :lowest
|
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.
|
18
|
-
def matches(_ext)
|
19
|
-
true
|
20
|
-
end
|
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.
|
27
|
-
def output_ext(ext)
|
28
|
-
ext
|
29
|
-
end
|
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.
|
36
|
-
def convert(content)
|
37
|
-
content
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Converters
|
5
|
+
# Identity converter. Returns same content as given.
|
6
|
+
# For more info on converters see https://jekyllrb.com/docs/plugins/converters/
|
7
|
+
class Identity < Converter
|
8
|
+
safe true
|
9
|
+
|
10
|
+
priority :lowest
|
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.
|
18
|
+
def matches(_ext)
|
19
|
+
true
|
20
|
+
end
|
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.
|
27
|
+
def output_ext(ext)
|
28
|
+
ext
|
29
|
+
end
|
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.
|
36
|
+
def convert(content)
|
37
|
+
content
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,199 +1,197 @@
|
|
1
|
-
#
|
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
|
-
#
|
70
|
-
|
71
|
-
module Jekyll
|
72
|
-
module Converters
|
73
|
-
class Markdown
|
74
|
-
class KramdownParser
|
75
|
-
CODERAY_DEFAULTS = {
|
76
|
-
"css" => "style",
|
77
|
-
"bold_every" => 10,
|
78
|
-
"line_numbers" => "inline",
|
79
|
-
"line_number_start" => 1,
|
80
|
-
"tab_width" => 4,
|
81
|
-
"wrap" => "div",
|
82
|
-
}.freeze
|
83
|
-
|
84
|
-
def initialize(config)
|
85
|
-
@main_fallback_highlighter = config["highlighter"] || "rouge"
|
86
|
-
@config = config["kramdown"] || {}
|
87
|
-
@highlighter = nil
|
88
|
-
setup
|
89
|
-
load_dependencies
|
90
|
-
end
|
91
|
-
|
92
|
-
# Setup and normalize the configuration:
|
93
|
-
# * Create Kramdown if it doesn't exist.
|
94
|
-
# * Set syntax_highlighter, detecting enable_coderay and merging
|
95
|
-
# highlighter if none.
|
96
|
-
# * Merge kramdown[coderay] into syntax_highlighter_opts stripping coderay_.
|
97
|
-
# * Make sure `syntax_highlighter_opts` exists.
|
98
|
-
|
99
|
-
def setup
|
100
|
-
@config["syntax_highlighter"] ||= highlighter
|
101
|
-
@config["syntax_highlighter_opts"] ||= {}
|
102
|
-
@config["syntax_highlighter_opts"]["default_lang"] ||= "plaintext"
|
103
|
-
@config["syntax_highlighter_opts"]["guess_lang"] = @config["guess_lang"]
|
104
|
-
@config["coderay"] ||= {} # XXX: Legacy.
|
105
|
-
modernize_coderay_config
|
106
|
-
end
|
107
|
-
|
108
|
-
def convert(content)
|
109
|
-
document = Kramdown::JekyllDocument.new(content, @config)
|
110
|
-
html_output = document.to_html
|
111
|
-
if @config["show_warnings"]
|
112
|
-
document.warnings.each do |warning|
|
113
|
-
Jekyll.logger.warn "Kramdown warning:", warning
|
114
|
-
end
|
115
|
-
end
|
116
|
-
html_output
|
117
|
-
end
|
118
|
-
|
119
|
-
private
|
120
|
-
|
121
|
-
def load_dependencies
|
122
|
-
require "kramdown-parser-gfm" if @config["input"] == "GFM"
|
123
|
-
|
124
|
-
if highlighter == "coderay"
|
125
|
-
Jekyll::External.require_with_graceful_fail("kramdown-syntax-coderay")
|
126
|
-
end
|
127
|
-
|
128
|
-
# `mathjax`
|
129
|
-
# kramdown itself.
|
130
|
-
if (math_engine = @config["math_engine"]) && math_engine != "mathjax"
|
131
|
-
Jekyll::External.require_with_graceful_fail("kramdown-math-#{math_engine}")
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
# config[kramdown][
|
136
|
-
# config[kramdown][enable_coderay] >
|
137
|
-
# config[highlighter]
|
138
|
-
# Where `enable_coderay` is now deprecated because Kramdown
|
139
|
-
# supports Rouge now too.
|
140
|
-
def highlighter
|
141
|
-
return @highlighter if @highlighter
|
142
|
-
|
143
|
-
if @config["syntax_highlighter"]
|
144
|
-
return @highlighter = @config[
|
145
|
-
"syntax_highlighter"
|
146
|
-
]
|
147
|
-
end
|
148
|
-
|
149
|
-
@highlighter =
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
#
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
end
|
199
|
-
end
|
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
|
+
#
|
70
|
+
|
71
|
+
module Jekyll
|
72
|
+
module Converters
|
73
|
+
class Markdown
|
74
|
+
class KramdownParser
|
75
|
+
CODERAY_DEFAULTS = {
|
76
|
+
"css" => "style",
|
77
|
+
"bold_every" => 10,
|
78
|
+
"line_numbers" => "inline",
|
79
|
+
"line_number_start" => 1,
|
80
|
+
"tab_width" => 4,
|
81
|
+
"wrap" => "div",
|
82
|
+
}.freeze
|
83
|
+
|
84
|
+
def initialize(config)
|
85
|
+
@main_fallback_highlighter = config["highlighter"] || "rouge"
|
86
|
+
@config = config["kramdown"] || {}
|
87
|
+
@highlighter = nil
|
88
|
+
setup
|
89
|
+
load_dependencies
|
90
|
+
end
|
91
|
+
|
92
|
+
# Setup and normalize the configuration:
|
93
|
+
# * Create Kramdown if it doesn't exist.
|
94
|
+
# * Set syntax_highlighter, detecting enable_coderay and merging
|
95
|
+
# highlighter if none.
|
96
|
+
# * Merge kramdown[coderay] into syntax_highlighter_opts stripping coderay_.
|
97
|
+
# * Make sure `syntax_highlighter_opts` exists.
|
98
|
+
|
99
|
+
def setup
|
100
|
+
@config["syntax_highlighter"] ||= highlighter
|
101
|
+
@config["syntax_highlighter_opts"] ||= {}
|
102
|
+
@config["syntax_highlighter_opts"]["default_lang"] ||= "plaintext"
|
103
|
+
@config["syntax_highlighter_opts"]["guess_lang"] = @config["guess_lang"]
|
104
|
+
@config["coderay"] ||= {} # XXX: Legacy.
|
105
|
+
modernize_coderay_config
|
106
|
+
end
|
107
|
+
|
108
|
+
def convert(content)
|
109
|
+
document = Kramdown::JekyllDocument.new(content, @config)
|
110
|
+
html_output = document.to_html
|
111
|
+
if @config["show_warnings"]
|
112
|
+
document.warnings.each do |warning|
|
113
|
+
Jekyll.logger.warn "Kramdown warning:", warning
|
114
|
+
end
|
115
|
+
end
|
116
|
+
html_output
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def load_dependencies
|
122
|
+
require "kramdown-parser-gfm" if @config["input"] == "GFM"
|
123
|
+
|
124
|
+
if highlighter == "coderay"
|
125
|
+
Jekyll::External.require_with_graceful_fail("kramdown-syntax-coderay")
|
126
|
+
end
|
127
|
+
|
128
|
+
# `mathjax` engine is bundled within kramdown-2.x and will be handled by
|
129
|
+
# kramdown itself.
|
130
|
+
if (math_engine = @config["math_engine"]) && math_engine != "mathjax"
|
131
|
+
Jekyll::External.require_with_graceful_fail("kramdown-math-#{math_engine}")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# config[kramdown][syntax_highlighter] >
|
136
|
+
# config[kramdown][enable_coderay] >
|
137
|
+
# config[highlighter]
|
138
|
+
# Where `enable_coderay` is now deprecated because Kramdown
|
139
|
+
# supports Rouge now too.
|
140
|
+
def highlighter
|
141
|
+
return @highlighter if @highlighter
|
142
|
+
|
143
|
+
if @config["syntax_highlighter"]
|
144
|
+
return @highlighter = @config[
|
145
|
+
"syntax_highlighter"
|
146
|
+
]
|
147
|
+
end
|
148
|
+
|
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
|
+
)
|
154
|
+
|
155
|
+
"coderay"
|
156
|
+
else
|
157
|
+
@main_fallback_highlighter
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def strip_coderay_prefix(hash)
|
162
|
+
hash.each_with_object({}) do |(key, val), hsh|
|
163
|
+
cleaned_key = key.to_s.delete_prefix("coderay_")
|
164
|
+
|
165
|
+
if key != cleaned_key
|
166
|
+
Jekyll::Deprecator.deprecation_message(
|
167
|
+
"You are using '#{key}'. Normalizing to #{cleaned_key}."
|
168
|
+
)
|
169
|
+
end
|
170
|
+
|
171
|
+
hsh[cleaned_key] = val
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# If our highlighter is CodeRay we go in to merge the CodeRay defaults
|
176
|
+
# with your "coderay" key if it's there, deprecating it in the
|
177
|
+
# process of you using it.
|
178
|
+
def modernize_coderay_config
|
179
|
+
unless @config["coderay"].empty?
|
180
|
+
Jekyll::Deprecator.deprecation_message(
|
181
|
+
"You are using 'kramdown.coderay' in your configuration, " \
|
182
|
+
"please use 'syntax_highlighter_opts' instead."
|
183
|
+
)
|
184
|
+
|
185
|
+
@config["syntax_highlighter_opts"] = begin
|
186
|
+
strip_coderay_prefix(
|
187
|
+
@config["syntax_highlighter_opts"] \
|
188
|
+
.merge(CODERAY_DEFAULTS) \
|
189
|
+
.merge(@config["coderay"])
|
190
|
+
)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|