jekyll-highlight 1.0.3 → 1.0.4
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.
- checksums.yaml +4 -4
- data/lib/jekyll-highlight/highlight_tag.rb +14 -11
- data/lib/jekyll-highlight/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 173f25fad42453331ffe67273ef989a618c40c33
|
4
|
+
data.tar.gz: d3b267c082306e3f895c75d9c8ab8c976db00a11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c757b4cc2745a6d6967373ddd8f3f7aee97879c0c55c6c12c48eaa1c75bf090fcc0032171b8fc5d84f6e6cc322cee130b18f3f88a8e95236fdd241a8ce687a17
|
7
|
+
data.tar.gz: b6a3d2b54cb3c9be6a76745800088ebe8668e46b0410aabd0661b33955e857fe1283eb3aed40efd3a1666bd11c6beceaadaf0bc182144210de4f115480c5fc3a
|
@@ -8,8 +8,9 @@ module Jekyll
|
|
8
8
|
# forms: name, name=value, or name="<quoted list>"
|
9
9
|
#
|
10
10
|
# <quoted list> is a space-separated list of numbers
|
11
|
-
PARAM_SYNTAX =
|
11
|
+
PARAM_SYNTAX = /^([a-zA-Z0-9.+#_-]+)((\s+\w+(=(\w+|"([0-9]+\s)*[0-9]+"))?)*)$/
|
12
12
|
|
13
|
+
# rubocop:disable Style/GuardClause
|
13
14
|
def initialize(tag_name, markup, tokens)
|
14
15
|
super
|
15
16
|
if markup.strip =~ PARAM_SYNTAX
|
@@ -26,10 +27,11 @@ eos
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
30
|
+
# rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Style/DoubleNegation
|
29
31
|
def render(context)
|
30
32
|
prefix = context["highlighter_prefix"] || ""
|
31
33
|
suffix = context["highlighter_suffix"] || ""
|
32
|
-
code = super.to_s.gsub(
|
34
|
+
code = super.to_s.gsub(/\A(\n|\r)+|(\n|\r)+\z/, "")
|
33
35
|
|
34
36
|
is_safe = !!context.registers[:site].safe
|
35
37
|
|
@@ -54,7 +56,7 @@ eos
|
|
54
56
|
[:hl_lines, opts.fetch(:hl_lines, nil)],
|
55
57
|
[:linenos, opts.fetch(:linenos, nil)],
|
56
58
|
[:encoding, opts.fetch(:encoding, "utf-8")],
|
57
|
-
[:cssclass, opts.fetch(:cssclass, nil)]
|
59
|
+
[:cssclass, opts.fetch(:cssclass, nil)]
|
58
60
|
].reject { |f| f.last.nil? }]
|
59
61
|
else
|
60
62
|
opts
|
@@ -63,11 +65,12 @@ eos
|
|
63
65
|
|
64
66
|
private
|
65
67
|
|
68
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
66
69
|
def parse_options(input)
|
67
70
|
options = {}
|
68
71
|
unless input.empty?
|
69
72
|
# Split along 3 possible forms -- key="<quoted list>", key=value, or key
|
70
|
-
input.scan(
|
73
|
+
input.scan(/(?:\w="[^"]*"|\w=\w|\w)+/) do |opt|
|
71
74
|
key, value = opt.split("=")
|
72
75
|
# If a quoted list, convert to array
|
73
76
|
if value && value.include?("\"")
|
@@ -88,8 +91,8 @@ eos
|
|
88
91
|
|
89
92
|
highlighted_code = Pygments.highlight(
|
90
93
|
code,
|
91
|
-
:
|
92
|
-
:
|
94
|
+
lexer: @lang,
|
95
|
+
options: sanitized_opts(@highlight_options, is_safe)
|
93
96
|
)
|
94
97
|
|
95
98
|
if highlighted_code.nil?
|
@@ -111,8 +114,8 @@ eos
|
|
111
114
|
def render_rouge(code)
|
112
115
|
Jekyll::External.require_with_graceful_fail("rouge")
|
113
116
|
formatter = Rouge::Formatters::HTML.new(
|
114
|
-
:
|
115
|
-
:
|
117
|
+
line_numbers: @highlight_options[:linenos],
|
118
|
+
wrap: false
|
116
119
|
)
|
117
120
|
lexer = Rouge::Lexer.find_fancy(@lang, code) || Rouge::Lexers::PlainText
|
118
121
|
formatter.format(lexer.lex(code))
|
@@ -124,8 +127,8 @@ eos
|
|
124
127
|
|
125
128
|
def add_code_tag(code)
|
126
129
|
code_attributes = [
|
127
|
-
"class=\"language-#{@lang.to_s.tr(
|
128
|
-
"data-lang=\"#{@lang}\""
|
130
|
+
"class=\"language-#{@lang.to_s.tr('+', '-')}\"",
|
131
|
+
"data-lang=\"#{@lang}\""
|
129
132
|
].join(" ")
|
130
133
|
"<figure class=\"highlight\"><pre><code #{code_attributes}>"\
|
131
134
|
"#{code.chomp}</code></pre></figure>"
|
@@ -134,4 +137,4 @@ eos
|
|
134
137
|
end
|
135
138
|
end
|
136
139
|
|
137
|
-
Liquid::Template.register_tag("highlight", Jekyll::Tags::HighlightBlock)
|
140
|
+
Liquid::Template.register_tag("highlight", Jekyll::Tags::HighlightBlock)
|