jekyll_pre 1.2.2 → 1.2.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 +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +84 -36
- data/lib/exec_tag.rb +43 -19
- data/lib/jekyll_pre/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e01bd13d91a64bf9b1dc9802cd11ef6c759985a30532daf8b3ace4618bfe634
|
4
|
+
data.tar.gz: 6d33733cf1f1d0267ba226dafd459807254fa10f5199f2b1358648f9f94ccc01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e1f5e2a5cb3beb928cc2d8ad09fd1274aff0c5085ac1ee1f014456aaefaa78d5711c2bd9046e9418737b7bff7b53b2e4f54856e5dbbb8fcd1d4f193757db0fc
|
7
|
+
data.tar.gz: 22747b92ec65bb6568a648c98a2a24417fd970daa012632ec596deca2232b0e994dffa7017792083d797c1ee6b2bc86b01b4b496d84525786ddcfd06769ade64
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,9 +4,9 @@ Jekyll_pre
|
|
4
4
|
|
5
5
|
This Jekyll plugin provides 3 new Liquid tags that work together:
|
6
6
|
|
7
|
-
* A `pre` block tag that can
|
7
|
+
* A `pre` block tag that can be displayed various ways.
|
8
8
|
```
|
9
|
-
{% pre [Options] [
|
9
|
+
{% pre [Options] [free text label] %}
|
10
10
|
Contents of pre tag
|
11
11
|
{% endpre %}
|
12
12
|
```
|
@@ -24,7 +24,7 @@ This Jekyll plugin provides 3 new Liquid tags that work together:
|
|
24
24
|
- {% pre This is a label %}<br>Contents of pre tag<br>{% endpre %}
|
25
25
|
- `number` – Number the lines
|
26
26
|
- `shell` – Equivalent to `label='Shell'`
|
27
|
-
- `style` – Apply CSS styles
|
27
|
+
- `style` – Apply inline CSS styles
|
28
28
|
|
29
29
|
The generated <pre></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.
|
30
30
|
|
@@ -32,32 +32,33 @@ This Jekyll plugin provides 3 new Liquid tags that work together:
|
|
32
32
|
and generates a <code>$</code> prompt if no content is provided.
|
33
33
|
```
|
34
34
|
{% pre %}
|
35
|
-
{% noselect [optional text string, defaults to $]%}
|
35
|
+
{% noselect [optional text string, defaults to $]%}Command
|
36
|
+
{% noselect unselectable output goes here %}
|
36
37
|
{% endpre %}
|
37
38
|
```
|
38
39
|
|
39
40
|
* An `exec` tag that executes shell commands and incorporates the command and its output into the content of the `pre` tag.
|
40
41
|
Output data is escaped, whitespace is condensed, and wrapped in the same `unselectable` class as does `unselectable`.
|
41
|
-
|
42
|
-
|
43
|
-
```
|
44
|
-
|
45
|
-
max-height: 500px;
|
46
|
-
}
|
42
|
+
```
|
43
|
+
{% exec [Options] [shell command] %}
|
44
|
+
```
|
45
|
+
`Options` are:
|
47
46
|
|
48
|
-
.
|
49
|
-
.
|
50
|
-
.
|
51
|
-
|
52
|
-
|
47
|
+
- `cd="relative/or/absolute/directory"` - Change to specified directory before executing shell command.
|
48
|
+
Environment variables in the directory path will be expanded.
|
49
|
+
- `no_escape` – Do not HTML escape the result of running the shell command.
|
50
|
+
- `no_strip` – Do not remove leading and trailing whitespace from the result.
|
51
|
+
- `die_if_nonzero` – Set `false` to treat non-zero return codes as non-fatal.
|
52
|
+
Instead of terminating Jekyll with an error message,
|
53
|
+
the message will be displayed as an error by the Jekyll logger,
|
54
|
+
and a red message will appear in place of the result on the web page.
|
55
|
+
- `die_if_error` – Set `false` to treat exceptions generated by this plugin as non-fatal.
|
56
|
+
Instead of terminating Jekyll with an error message, the message will be displayed as an error by the Jekyll logger.
|
53
57
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
user-select: none;
|
59
|
-
}
|
60
|
-
```
|
58
|
+
|
59
|
+
## CSS
|
60
|
+
See [`demo/assets/css/style.css`](demo/assets/css/style.css) for the CSS declarations,
|
61
|
+
between `/* Start of pre tag css */` and `/* End of pre tag css */`.
|
61
62
|
|
62
63
|
|
63
64
|
## Additional Information
|
@@ -80,6 +81,7 @@ And then execute:
|
|
80
81
|
|
81
82
|
|
82
83
|
## Usage
|
84
|
+
The following examples are rendered on [my website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#jekyll_pre).
|
83
85
|
|
84
86
|
### Example 1
|
85
87
|
This example does not generate a copy button and does not demonstrate `noselect`.
|
@@ -151,20 +153,70 @@ Which renders as:
|
|
151
153
|

|
152
154
|
|
153
155
|
|
154
|
-
###
|
155
|
-
|
156
|
+
### Example 5
|
157
|
+
A regular expression can be passed to the `highlight` option.
|
158
|
+
This causes text that matches the regex pattern to be wrapped within a <span class="bg_yellow"></span> tag.
|
159
|
+
|
160
|
+
The CSS stylesheet used for this page contains the following:
|
156
161
|
|
157
162
|
```css
|
158
|
-
.
|
159
|
-
|
163
|
+
.bg_yellow {
|
164
|
+
background-color: yellow;
|
165
|
+
padding: 2px;
|
160
166
|
}
|
167
|
+
```
|
168
|
+
|
169
|
+
This example demonstrates highlighting text that matches a regular expression. Regular expressions match against lines, which are delimited via newlines (\n).
|
170
|
+
|
171
|
+
```
|
172
|
+
{% pre copyButton highlight="Line 2" %}
|
173
|
+
Line 1
|
174
|
+
Line 2
|
175
|
+
Line 3
|
176
|
+
Line 4
|
177
|
+
Line 5
|
178
|
+
Line 6
|
179
|
+
Line 7
|
180
|
+
{% endpre %}
|
181
|
+
```
|
182
|
+
|
183
|
+
|
184
|
+
### Example 6
|
185
|
+
Regular expressions match against lines, which are delimited via newlines (`\n`).
|
186
|
+
Thus to match an entire line that contains a phrase, specify the regex as `.*phrase.*`.
|
187
|
+
The following matches 3 possible phrases (`2`, `4` or `6`), then selects the entire line if matched.
|
188
|
+
|
189
|
+
```
|
190
|
+
{% pre copyButton highlight=".*(2|4|6).*" %}
|
191
|
+
Line 1
|
192
|
+
Line 2
|
193
|
+
Line 3
|
194
|
+
Line 4
|
195
|
+
Line 5
|
196
|
+
Line 6
|
197
|
+
Line 7
|
198
|
+
{% endpre %}
|
199
|
+
```
|
200
|
+
|
201
|
+
|
202
|
+
### Example 7
|
203
|
+
This example floats an image to the right.
|
204
|
+
The `jekyll_pre plugin`’s `clear` option moves the generated HTML below the image.
|
161
205
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
206
|
+
```
|
207
|
+
<img src="jekyll.webp" style="float: right; width: 100px; height: auto;">
|
208
|
+
{% pre clear copyButton label='Clear example' %}
|
209
|
+
Using clear, copyButton and label parameters
|
210
|
+
{% endpre %}
|
211
|
+
```
|
212
|
+
|
213
|
+
### Example 8
|
214
|
+
The following executes `ls -alF /` and displays the output.
|
215
|
+
|
216
|
+
```
|
217
|
+
{% pre clear copyButton label='Exec without error' %}
|
218
|
+
{% noselect %}{% exec die_if_nonzero=false ls -alF / %}
|
219
|
+
{% endpre %}
|
168
220
|
```
|
169
221
|
|
170
222
|
|
@@ -208,11 +260,7 @@ A test website is provided in the `demo` directory.
|
|
208
260
|
|
209
261
|
### Build and Install Locally
|
210
262
|
To build and install this gem onto your local machine, run:
|
211
|
-
```shell
|
212
|
-
$ rake install:local
|
213
|
-
```
|
214
263
|
|
215
|
-
The following also does the same thing:
|
216
264
|
```shell
|
217
265
|
$ bundle exec rake install
|
218
266
|
```
|
data/lib/exec_tag.rb
CHANGED
@@ -7,18 +7,13 @@ module ExecTag
|
|
7
7
|
|
8
8
|
def render_impl
|
9
9
|
parse_args
|
10
|
-
|
11
10
|
command = @helper.remaining_markup
|
12
|
-
response =
|
13
|
-
if
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@logger.error { msg }
|
20
|
-
response = "<span class='error'>Error: error code #{$CHILD_STATUS.exitstatus}</span>"
|
21
|
-
end
|
11
|
+
response = run_command(command)
|
12
|
+
response = if @child_status.success?
|
13
|
+
compress(response)
|
14
|
+
else
|
15
|
+
handle_error(command)
|
16
|
+
end
|
22
17
|
|
23
18
|
<<~END_OUTPUT
|
24
19
|
#{Rack::Utils.escape_html(command)}
|
@@ -41,22 +36,51 @@ module ExecTag
|
|
41
36
|
result
|
42
37
|
end
|
43
38
|
|
39
|
+
def die(msg)
|
40
|
+
msg_no_html = remove_html_tags(msg)
|
41
|
+
@logger.error("#{@page['path']} - #{msg_no_html}")
|
42
|
+
raise PreError, "#{@page['path']} - #{msg_no_html.red}", []
|
43
|
+
end
|
44
|
+
|
45
|
+
def handle_error(command)
|
46
|
+
msg0 = "Error: executing '#{command}'"
|
47
|
+
msg0 += " in directory '#{@cd}'" if @cd
|
48
|
+
msg = <<~END_MSG
|
49
|
+
#{msg0} on line #{@line_number} (after front matter) of #{@page['path']} returned error code #{@child_status.exitstatus}
|
50
|
+
END_MSG
|
51
|
+
raise PreError, msg.red, [] if @die_if_nonzero
|
52
|
+
|
53
|
+
@logger.error { msg }
|
54
|
+
"<span class='error'>Error code #{@child_status.exitstatus}</span>"
|
55
|
+
end
|
56
|
+
|
44
57
|
def parse_args
|
58
|
+
@cd = @helper.parameter_specified? 'cd'
|
59
|
+
@cd = JekyllPluginHelper.expand_env(@cd) if @cd
|
60
|
+
|
45
61
|
@no_escape = @helper.parameter_specified? 'no_escape'
|
46
62
|
@no_strip = @helper.parameter_specified? 'no_strip'
|
47
63
|
@die_if_nonzero = @helper.parameter_specified?('die_if_nonzero') # Implies die_if_error
|
48
64
|
@die_if_error = @helper.parameter_specified?('die_if_error') | @die_if_nonzero
|
49
65
|
end
|
50
66
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
67
|
+
# References @cd
|
68
|
+
# Defines @child_status
|
69
|
+
# @return result of running command
|
70
|
+
# @param command [String] Shell command to execute
|
71
|
+
def run_command(command)
|
72
|
+
result = if @cd
|
73
|
+
Dir.chdir(@cd) do
|
74
|
+
`#{command}`
|
75
|
+
end
|
76
|
+
else
|
77
|
+
`#{command}`
|
78
|
+
end
|
79
|
+
@child_status = $CHILD_STATUS
|
80
|
+
result
|
81
|
+
end
|
55
82
|
|
56
|
-
|
57
|
-
msg_no_html = remove_html_tags(msg)
|
58
|
-
@logger.error("#{@page['path']} - #{msg_no_html}")
|
59
|
-
raise PreError, "#{@page['path']} - #{msg_no_html.red}", []
|
83
|
+
JekyllPluginHelper.register(self, 'exec')
|
60
84
|
end
|
61
85
|
|
62
86
|
def remove_html_tags(string)
|
data/lib/jekyll_pre/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_pre
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Slinn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|