jekyll_flexible_include 2.0.9 → 2.0.13

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
  SHA256:
3
- metadata.gz: b71142b75599a60998290ed57afbe3231330bf42dba89c7f892e3e08e3eb07e2
4
- data.tar.gz: e1cf42634742f63c2f6f44e4e800093003fbe9a01e47f12414c8876c9663f0d1
3
+ metadata.gz: c55ae38bb0ea6af18a3bff7de442e9c75229e3fca45991a15b5b0d829606e417
4
+ data.tar.gz: 6cba87719d81e829c0b3e68f9483d99b1daed9454c740b815d6c098c629ac003
5
5
  SHA512:
6
- metadata.gz: 1456652118883acd55de272df6c00c8ce29c42031609282ffe95ff043c15f5c57f9f293d23490edf78267dc672408045018e69cb2edcd6be144cd214b180b9a4
7
- data.tar.gz: 88a9c4d75a15fdd84980816a266fbfd12d6e1e81cfac041881393b33d015ddbcfad30c0a2d1e4ae7b5ea09048838a0fddfc7352db508a6520543b4cca67ab06a
6
+ metadata.gz: 9c470001c4f5e933c0ec122792f9bc6cccb34b0a7e20e6886875e5a5a41c8de64c6722347ff9cf5a6e586aef9859106d73ed90863cdb91fe89254beffd510294
7
+ data.tar.gz: a6e79fcb6d7eb7834b7de448d385940818870be9021454e3a8ef476fae4c2a90f0c944ba2f6d8d4d2ab5514a122adbe2629cfbc5af387e6681af2b8eff9f1fba
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
+ ## 2.0.13 / 2022-04-24
2
+ * Added `highlight` regex option, for highlighting
3
+ * Added `number` option, for numbered lines
4
+
5
+ ## 2.0.12 / 2022-04-22
6
+ * Exits with an error message if an environment variable included in the value of `FLEXIBLE_INCLUDE_PATHS` is undefined.
7
+
8
+ ## 2.0.11 / 2022-04-15
9
+ * Added & => & to the escaped characters
10
+
11
+ ## 2.0.10 / 2022-04-15
12
+ * Fixed nil pointer
13
+
1
14
  ## 2.0.9 / 2022-04-15
2
- * Displays elapsed time to scan files; only scans when the gem is first used.
15
+ * Changed how path matching was implemented.
3
16
 
4
17
  ## 2.0.8 / 2022-04-14
5
18
  * Added the ability to restrict arbitrary command execution, and specify the allowable directories to read from.
data/README.md CHANGED
@@ -37,6 +37,7 @@ Note that the [square brackets] merely indicate optional parameters and are not
37
37
 
38
38
  ### Options
39
39
  * `do_not_escape` includes the content without HTML escaping it.
40
+ * `highlight='regex pattern here'` wraps content matching the regex pattern within a `<span class='bg_yellow'></span>` tag.
40
41
  * `pre` causes the included file to be wrapped inside a &lt;pre>&lt;/pre> tag, no label is generated. The &lt;pre>&lt;/pre> tag has an `data-lt-active="false"` attribute, so [LanguageTool](https://forum.languagetool.org/t/avoid-spell-check-on-certain-html-inputs-manually/3944) does not check the spelling or grammar of the contents.
41
42
 
42
43
  The following options imply `pre`:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllFlexibleIncludePluginVersion
4
- VERSION = "2.0.9"
4
+ VERSION = "2.0.13"
5
5
  end
@@ -11,13 +11,16 @@ module JekyllFlexibleIncludeName
11
11
  PLUGIN_NAME = "flexible_include"
12
12
  end
13
13
 
14
+ class FlexibleError < StandardError
15
+ end
16
+
14
17
  class FlexibleInclude < Liquid::Tag
15
18
  FlexibleIncludeError = Class.new(Liquid::Error)
16
19
 
17
20
  @read_regexes = nil
18
21
 
19
22
  def self.normalize_path(path)
20
- JekyllTagHelper.expand_env(path)
23
+ JekyllTagHelper.expand_env(path, die_if_undefined: true)
21
24
  .gsub("~", Dir.home)
22
25
  end
23
26
 
@@ -27,7 +30,8 @@ class FlexibleInclude < Liquid::Tag
27
30
  @execution_denied = ENV['DISABLE_FLEXIBLE_INCLUDE']
28
31
 
29
32
  unless @read_regexes
30
- read_paths = normalize_path(ENV['FLEXIBLE_INCLUDE_PATHS'])
33
+ flexible_include_paths = ENV['FLEXIBLE_INCLUDE_PATHS']
34
+ read_paths = normalize_path(flexible_include_paths) if flexible_include_paths
31
35
  if read_paths
32
36
  @read_regexes = read_paths.split(":").map do |path|
33
37
  abs_path = path.start_with?('/') ? path : (Pathname.new(Dir.pwd) + path).to_s
@@ -43,6 +47,20 @@ class FlexibleInclude < Liquid::Tag
43
47
  @read_regexes.find { |regex| regex.match(normalize_path(path)) }
44
48
  end
45
49
 
50
+ def self.number_content(content)
51
+ lines = content.split("\n")
52
+ digits = lines.length.to_s.length
53
+ i = 0
54
+ numbered_content = lines.map do |line|
55
+ i += 1
56
+ number = i.to_s.rjust(digits, " ")
57
+ "<span class='unselectable numbered_line'> #{number}: </span>#{line}"
58
+ end
59
+ result = numbered_content.join("\n")
60
+ result += "\n" unless result.end_with?("\n")
61
+ result
62
+ end
63
+
46
64
  # @param tag_name [String] the name of the tag, which we already know.
47
65
  # @param markup [String] the arguments from the tag, as a single string.
48
66
  # @param parse_context [Liquid::ParseContext] hash that stores Liquid options.
@@ -64,10 +82,12 @@ class FlexibleInclude < Liquid::Tag
64
82
  @do_not_escape = @helper.parameter_specified? "do_not_escape"
65
83
  @download = @helper.parameter_specified? "download"
66
84
  @dark = " dark" if @helper.parameter_specified?("dark")
85
+ @highlight_pattern = @helper.parameter_specified? "highlight"
67
86
  @label = @helper.parameter_specified? "label"
87
+ @number_lines = @helper.parameter_specified? "number"
68
88
  @label_specified = @label
69
89
  @copy_button = @helper.parameter_specified? "copyButton"
70
- @pre = @copy_button || @dark || @download || @label_specified || @helper.parameter_specified?("pre") # Download or label implies pre
90
+ @pre = @copy_button || @dark || @download || @label_specified || @number_lines || @helper.parameter_specified?("pre") # Download or label implies pre
71
91
 
72
92
  filename = @helper.parameter_specified? "file"
73
93
  filename ||= @helper.params.first # Do this after all options have been checked for
@@ -116,6 +136,10 @@ class FlexibleInclude < Liquid::Tag
116
136
  "<p style='color: white; background-color: red; padding: 2pt 1em 2pt 1em;'>#{msg}</p>"
117
137
  end
118
138
 
139
+ def highlight(content, pattern)
140
+ content.gsub(Regexp::new(pattern), "<span class='bg_yellow'>\\0</span>")
141
+ end
142
+
119
143
  def read_file(file)
120
144
  File.read(file)
121
145
  end
@@ -129,6 +153,8 @@ class FlexibleInclude < Liquid::Tag
129
153
  def render_completion(path, contents)
130
154
  contents ||= read_file(path)
131
155
  contents2 = @do_not_escape ? contents : JekyllTagHelper.escape_html(contents)
156
+ contents2 = highlight(contents2, @highlight_pattern) if @highlight_pattern
157
+ contents2 = FlexibleInclude.number_content(contents2) if @number_lines
132
158
  @pre ? wrap_in_pre(path, contents2) : contents2
133
159
  end
134
160
 
@@ -7,12 +7,19 @@ class JekyllTagHelper
7
7
  attr_reader :argv, :liquid_context, :logger, :params, :tag_name
8
8
 
9
9
  def self.escape_html(string)
10
- string.gsub("{", "&#123;").gsub("}", "&#125;").gsub("<", "&lt;")
10
+ string.gsub("&", "&amp;")
11
+ .gsub("{", "&#123;")
12
+ .gsub("}", "&#125;")
13
+ .gsub("<", "&lt;")
11
14
  end
12
15
 
13
16
  # Expand a environment variable reference
14
- def self.expand_env(str)
15
- str.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) { ENV[Regexp.last_match(1)] }
17
+ def self.expand_env(str, die_if_undefined=false)
18
+ str.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do
19
+ envar = Regexp.last_match(1)
20
+ raise FlexibleError, "flexible_include error: #{envar} is undefined".red, [] if !ENV.key?(envar) && die_if_undefined # Suppress stack trace
21
+ ENV[envar]
22
+ end
16
23
  end
17
24
 
18
25
  # strip leading and trailing quotes if present
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_flexible_include
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.9
4
+ version: 2.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2022-04-15 00:00:00.000000000 Z
13
+ date: 2022-04-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jekyll