jekyll_flexible_include 2.0.11 → 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: f3c2d80bab20b338d7635734938862e2ed99af858dc8f4967e7f0995fc0e5304
4
- data.tar.gz: 3683ddcebf92f60dd12955e34eb64a910e8d51a16e46fa2b8c40fafb5b33b682
3
+ metadata.gz: c55ae38bb0ea6af18a3bff7de442e9c75229e3fca45991a15b5b0d829606e417
4
+ data.tar.gz: 6cba87719d81e829c0b3e68f9483d99b1daed9454c740b815d6c098c629ac003
5
5
  SHA512:
6
- metadata.gz: 694653b9d9104793c425af90a2f93be38ee822c399bc60b1ce1bb012f70ea8af0268a8d4679353a4aab1f0dcd143b8738f58c74e094dc973b27081ac46690abd
7
- data.tar.gz: 38b218be26c2bef642f13bf313150ef92676d214d5ade4b8333d936e47883f5b2a8b941b4a67f58427794706b68e976cd04847a1efba286dabe3d25eb914b3a9
6
+ metadata.gz: 9c470001c4f5e933c0ec122792f9bc6cccb34b0a7e20e6886875e5a5a41c8de64c6722347ff9cf5a6e586aef9859106d73ed90863cdb91fe89254beffd510294
7
+ data.tar.gz: a6e79fcb6d7eb7834b7de448d385940818870be9021454e3a8ef476fae4c2a90f0c944ba2f6d8d4d2ab5514a122adbe2629cfbc5af387e6681af2b8eff9f1fba
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
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
+
1
8
  ## 2.0.11 / 2022-04-15
2
9
  * Added & => & to the escaped characters
3
10
 
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.11"
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
 
@@ -44,6 +47,20 @@ class FlexibleInclude < Liquid::Tag
44
47
  @read_regexes.find { |regex| regex.match(normalize_path(path)) }
45
48
  end
46
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
+
47
64
  # @param tag_name [String] the name of the tag, which we already know.
48
65
  # @param markup [String] the arguments from the tag, as a single string.
49
66
  # @param parse_context [Liquid::ParseContext] hash that stores Liquid options.
@@ -65,10 +82,12 @@ class FlexibleInclude < Liquid::Tag
65
82
  @do_not_escape = @helper.parameter_specified? "do_not_escape"
66
83
  @download = @helper.parameter_specified? "download"
67
84
  @dark = " dark" if @helper.parameter_specified?("dark")
85
+ @highlight_pattern = @helper.parameter_specified? "highlight"
68
86
  @label = @helper.parameter_specified? "label"
87
+ @number_lines = @helper.parameter_specified? "number"
69
88
  @label_specified = @label
70
89
  @copy_button = @helper.parameter_specified? "copyButton"
71
- @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
72
91
 
73
92
  filename = @helper.parameter_specified? "file"
74
93
  filename ||= @helper.params.first # Do this after all options have been checked for
@@ -117,6 +136,10 @@ class FlexibleInclude < Liquid::Tag
117
136
  "<p style='color: white; background-color: red; padding: 2pt 1em 2pt 1em;'>#{msg}</p>"
118
137
  end
119
138
 
139
+ def highlight(content, pattern)
140
+ content.gsub(Regexp::new(pattern), "<span class='bg_yellow'>\\0</span>")
141
+ end
142
+
120
143
  def read_file(file)
121
144
  File.read(file)
122
145
  end
@@ -130,6 +153,8 @@ class FlexibleInclude < Liquid::Tag
130
153
  def render_completion(path, contents)
131
154
  contents ||= read_file(path)
132
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
133
158
  @pre ? wrap_in_pre(path, contents2) : contents2
134
159
  end
135
160
 
@@ -14,8 +14,12 @@ class JekyllTagHelper
14
14
  end
15
15
 
16
16
  # Expand a environment variable reference
17
- def self.expand_env(str)
18
- 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
19
23
  end
20
24
 
21
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.11
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