jekyll-highlight 1.0.2 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f3ae31657ba202f452f0e6b665a375e044ce2e5
4
- data.tar.gz: 0f7f56bbff4fdf6f0f3a6f8bbd0e6af34c25d5a8
3
+ metadata.gz: 45ebe4dc194571ffd88159276b6bd6701803822c
4
+ data.tar.gz: 7055928401b0aa6b1fb4392c318ab86e9583fc87
5
5
  SHA512:
6
- metadata.gz: cc0507dca6dab255e3a18b14175144a63cfe3aa61e3c05e3e36c314cc52517a311b41fbd20287ac7ff18ed7fb444a0e1c11383817775ecb0c731ef1c940dfc06
7
- data.tar.gz: c2d61f515d591222543cd89af2ddd72b7dd10ade1b2e0ac56a047240adb2b5f284122461984c88678552479386f4a31ce0625c8b361e7a0c9496eee518fc0b7e
6
+ metadata.gz: f68b5518e69eabe314a4c649d628b9ca7d079727055b6a6bb0e87a5e5daa6dc06642c8e3129fc78bf08db6cc5189be5b109dbd16691766b04e5ea318a9c30d39
7
+ data.tar.gz: cda0eae353f1728b5d3e28f562d595d17f7c6cbf6d6617037df163bd9c3426da48155f6ead4b623281bde71bf6d783ef37f0cae784a25f768d57007e3e6ee12c
@@ -8,12 +8,15 @@ 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 = %r{/^([a-zA-Z0-9.+#_-]+)((\s+\w+(=(\w+|"([0-9]+\s)*[0-9]+"))?)*)$/}
11
+ PARAM_SYNTAX = %r!^([a-zA-Z0-9.+#_-]+)((\s+\w+(=(\w+|"([0-9]+\s)*[0-9]+"))?)*)$!
12
12
 
13
13
  def initialize(tag_name, markup, tokens)
14
14
  super
15
- unless markup.strip =~ PARAM_SYNTAX
16
- return raise SyntaxError, <<-eos
15
+ if markup.strip =~ PARAM_SYNTAX
16
+ @lang = Regexp.last_match(1).downcase
17
+ @highlight_options = parse_options(Regexp.last_match(2))
18
+ else
19
+ raise SyntaxError, <<-eos
17
20
  Syntax Error in tag 'highlight' while parsing the following markup:
18
21
 
19
22
  #{markup}
@@ -21,15 +24,12 @@ Syntax Error in tag 'highlight' while parsing the following markup:
21
24
  Valid syntax: highlight <lang> [linenos]
22
25
  eos
23
26
  end
24
- @lang = Regexp.last_match(1).downcase
25
- @highlight_options = parse_options(Regexp.last_match(2))
26
27
  end
27
28
 
28
- # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Style/DoubleNegation
29
29
  def render(context)
30
30
  prefix = context["highlighter_prefix"] || ""
31
31
  suffix = context["highlighter_suffix"] || ""
32
- code = super.to_s.gsub(%r{/\A(\n|\r)+|(\n|\r)+\z/}, "")
32
+ code = super.to_s.gsub(%r!\A(\n|\r)+|(\n|\r)+\z!, "")
33
33
 
34
34
  is_safe = !!context.registers[:site].safe
35
35
 
@@ -54,7 +54,7 @@ eos
54
54
  [:hl_lines, opts.fetch(:hl_lines, nil)],
55
55
  [:linenos, opts.fetch(:linenos, nil)],
56
56
  [:encoding, opts.fetch(:encoding, "utf-8")],
57
- [:cssclass, opts.fetch(:cssclass, nil)]
57
+ [:cssclass, opts.fetch(:cssclass, nil)],
58
58
  ].reject { |f| f.last.nil? }]
59
59
  else
60
60
  opts
@@ -63,12 +63,11 @@ eos
63
63
 
64
64
  private
65
65
 
66
- # rubocop:disable Metrics/CyclomaticComplexity
67
66
  def parse_options(input)
68
67
  options = {}
69
68
  unless input.empty?
70
69
  # Split along 3 possible forms -- key="<quoted list>", key=value, or key
71
- input.scan(%r{/(?:\w="[^"]*"|\w=\w|\w)+/}) do |opt|
70
+ input.scan(%r!(?:\w="[^"]*"|\w=\w|\w)+!) do |opt|
72
71
  key, value = opt.split("=")
73
72
  # If a quoted list, convert to array
74
73
  if value && value.include?("\"")
@@ -89,8 +88,8 @@ eos
89
88
 
90
89
  highlighted_code = Pygments.highlight(
91
90
  code,
92
- lexer: @lang,
93
- options: sanitized_opts(@highlight_options, is_safe)
91
+ :lexer => @lang,
92
+ :options => sanitized_opts(@highlight_options, is_safe)
94
93
  )
95
94
 
96
95
  if highlighted_code.nil?
@@ -112,8 +111,8 @@ eos
112
111
  def render_rouge(code)
113
112
  Jekyll::External.require_with_graceful_fail("rouge")
114
113
  formatter = Rouge::Formatters::HTML.new(
115
- line_numbers: @highlight_options[:linenos],
116
- wrap: false
114
+ :line_numbers => @highlight_options[:linenos],
115
+ :wrap => false
117
116
  )
118
117
  lexer = Rouge::Lexer.find_fancy(@lang, code) || Rouge::Lexers::PlainText
119
118
  formatter.format(lexer.lex(code))
@@ -125,8 +124,8 @@ eos
125
124
 
126
125
  def add_code_tag(code)
127
126
  code_attributes = [
128
- "class=\"language-#{@lang.to_s.tr('+', '-')}\"",
129
- "data-lang=\"#{@lang}\""
127
+ "class=\"language-#{@lang.to_s.tr("+", "-")}\"",
128
+ "data-lang=\"#{@lang}\"",
130
129
  ].join(" ")
131
130
  "<figure class=\"highlight\"><pre><code #{code_attributes}>"\
132
131
  "#{code.chomp}</code></pre></figure>"
@@ -135,4 +134,4 @@ eos
135
134
  end
136
135
  end
137
136
 
138
- Liquid::Template.register_tag("highlight", Jekyll::Tags::HighlightBlock)
137
+ Liquid::Template.register_tag("highlight", Jekyll::Tags::HighlightBlock)
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Highlight
3
- VERSION = "1.0.2".freeze
3
+ VERSION = "1.0.3".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-highlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Torgny Bjers