jekyll_pre 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -3
- data/CHANGELOG.md +4 -0
- data/jekyll_pre.gemspec +2 -2
- data/lib/jekyll_pre/version.rb +1 -1
- data/lib/jekyll_pre.rb +42 -29
- data/lib/jekyll_tag_helper.rb +11 -9
- metadata +7 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3eced8ae5430c67a303f08c90a38caf16c46efbad4e11232aa95ed9580c2f98
|
4
|
+
data.tar.gz: 9370b4fab76dc5ba5487c0d0876907ed9366d0f1e777e63ca8250121a9a32533
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fc327f37d0c5dc7f54ba78837984a05603ae24bbdee5e888eebdb01bc8d377ecd08bbc4b18a68c97a9bd3f1272f359cb8da53ee7a2143938793d5dca298fb31
|
7
|
+
data.tar.gz: 656acb136598d957e9b129a2ebd71cfb905f63191c6c0c09eb0565c9070c71d5790b1319289b6ac70d71f15b8710a1af5e693240102f10f5c4ecce0068784252
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 1.1.5
|
2
|
+
* Added `class` and `style` options to allow for specifying additional CSS classes and inline CSS
|
3
|
+
* Added `clear` option to ensure no images overlap the pre output
|
4
|
+
|
1
5
|
## 1.1.4
|
2
6
|
* Added `highlight` regex option
|
3
7
|
* Now using `lib/jekyll_tag_helper.rb` to parse markup
|
data/jekyll_pre.gemspec
CHANGED
@@ -39,10 +39,10 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_dependency "key-value-parser"
|
40
40
|
spec.add_dependency "shellwords"
|
41
41
|
|
42
|
-
spec.add_development_dependency "debase"
|
42
|
+
# spec.add_development_dependency "debase"
|
43
43
|
# spec.add_development_dependency "rubocop-jekyll"
|
44
44
|
# spec.add_development_dependency "rubocop-rake"
|
45
45
|
# spec.add_development_dependency "rubocop-rspec"
|
46
|
-
spec.add_development_dependency "ruby-debug-ide"
|
46
|
+
# spec.add_development_dependency "ruby-debug-ide"
|
47
47
|
end
|
48
48
|
# rubocop:enable Metrics/BlockLength
|
data/lib/jekyll_pre/version.rb
CHANGED
data/lib/jekyll_pre.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'liquid'
|
4
|
+
require 'jekyll_plugin_logger'
|
5
5
|
require 'key_value_parser'
|
6
|
-
require
|
7
|
-
require_relative
|
8
|
-
require_relative
|
6
|
+
require 'shellwords'
|
7
|
+
require_relative 'jekyll_pre/version'
|
8
|
+
require_relative 'jekyll_tag_helper'
|
9
9
|
|
10
10
|
module JekyllPluginPreName
|
11
|
-
PLUGIN_NAME =
|
11
|
+
PLUGIN_NAME = 'jekyll_pre'
|
12
12
|
end
|
13
13
|
|
14
14
|
# """
|
@@ -37,36 +37,46 @@ class PreTagBlock < Liquid::Block
|
|
37
37
|
"alt='Copy to clipboard' style='width: 13px'></button>"
|
38
38
|
|
39
39
|
def self.highlight(content, pattern)
|
40
|
-
content.gsub(Regexp
|
40
|
+
content.gsub(Regexp.new(pattern), "<span class='bg_yellow'>\\0</span>")
|
41
41
|
end
|
42
42
|
|
43
43
|
def self.make_copy_button(pre_id)
|
44
44
|
"#{@@prefix}'##{pre_id}'#{@@suffix}"
|
45
45
|
end
|
46
46
|
|
47
|
-
def self.make_pre(make_copy_button, number_lines, label, dark, highlight_pattern, content) # rubocop:disable Metrics/ParameterLists
|
48
|
-
|
47
|
+
def self.make_pre(make_copy_button, number_lines, label, dark, highlight_pattern, css_class, style, clear, content) # rubocop:disable Metrics/ParameterLists, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
|
48
|
+
pre_clear = label_clear = ''
|
49
|
+
if clear
|
50
|
+
if label.to_s.empty?
|
51
|
+
pre_clear = ' clear'
|
52
|
+
else
|
53
|
+
label_clear = ' clear'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
css_class = css_class ? " #{css_class}" : ''
|
57
|
+
style = style ? " style='#{style}'" : ''
|
58
|
+
dark_label = ' darkLabel' if dark
|
49
59
|
label = if label.to_s.empty?
|
50
|
-
|
51
|
-
elsif label.to_s.downcase.strip ==
|
52
|
-
"<div class='codeLabel unselectable#{dark_label}' data-lt-active='false'>Shell</div>"
|
60
|
+
''
|
61
|
+
elsif label.to_s.downcase.strip == 'shell'
|
62
|
+
"<div class='codeLabel unselectable#{dark_label}#{label_clear}' data-lt-active='false'>Shell</div>"
|
53
63
|
else
|
54
|
-
"<div class='codeLabel unselectable#{dark_label}' data-lt-active='false'>#{label}</div>"
|
64
|
+
"<div class='codeLabel unselectable#{dark_label}#{label_clear}' data-lt-active='false'>#{label}</div>"
|
55
65
|
end
|
56
66
|
pre_id = "id#{SecureRandom.hex(6)}"
|
57
|
-
copy_button = make_copy_button ? PreTagBlock.make_copy_button(pre_id) :
|
67
|
+
copy_button = make_copy_button ? PreTagBlock.make_copy_button(pre_id) : ''
|
58
68
|
content = PreTagBlock.highlight(content, highlight_pattern) if highlight_pattern
|
59
69
|
content = PreTagBlock.number_content(content) if number_lines
|
60
|
-
"#{label}<pre data-lt-active='false' class='maxOneScreenHigh copyContainer#{dark}' id='#{pre_id}'>#{copy_button}#{content.strip}</pre>"
|
70
|
+
"#{label}<pre data-lt-active='false' class='maxOneScreenHigh copyContainer#{dark}#{pre_clear}#{css_class}'#{style} id='#{pre_id}'>#{copy_button}#{content.strip}</pre>"
|
61
71
|
end
|
62
72
|
|
63
|
-
def self.number_content(content)
|
73
|
+
def self.number_content(content) # rubocop:disable Metrics/MethodLength
|
64
74
|
lines = content.split("\n")
|
65
75
|
digits = lines.length.to_s.length
|
66
76
|
i = 0
|
67
77
|
numbered_content = lines.map do |line|
|
68
78
|
i += 1
|
69
|
-
number = i.to_s.rjust(digits,
|
79
|
+
number = i.to_s.rjust(digits, ' ')
|
70
80
|
"<span class='unselectable numbered_line'> #{number}: </span>#{line}"
|
71
81
|
end
|
72
82
|
result = numbered_content.join("\n")
|
@@ -84,7 +94,7 @@ class PreTagBlock < Liquid::Block
|
|
84
94
|
# @return [void]
|
85
95
|
def initialize(_tag_name, markup, _tokens)
|
86
96
|
super
|
87
|
-
markup =
|
97
|
+
markup = '' if markup.nil?
|
88
98
|
markup.strip!
|
89
99
|
|
90
100
|
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
@@ -94,21 +104,24 @@ class PreTagBlock < Liquid::Block
|
|
94
104
|
# Method prescribed by the Jekyll plugin lifecycle.
|
95
105
|
# @param liquid_context [Liquid::Context]
|
96
106
|
# @return [String]
|
97
|
-
def render(liquid_context)
|
107
|
+
def render(liquid_context) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
98
108
|
content = super
|
99
109
|
@helper.liquid_context = liquid_context
|
100
110
|
|
101
|
-
@
|
102
|
-
@
|
103
|
-
@
|
104
|
-
@
|
105
|
-
@
|
111
|
+
@clear = @helper.parameter_specified?('clear')
|
112
|
+
@class = @helper.parameter_specified?('class')
|
113
|
+
@highlight = @helper.parameter_specified? 'highlight'
|
114
|
+
@make_copy_button = @helper.parameter_specified? 'copyButton'
|
115
|
+
@number_lines = @helper.parameter_specified? 'number'
|
116
|
+
@dark = ' dark' if @helper.parameter_specified? 'dark'
|
117
|
+
@label = @helper.parameter_specified? 'label'
|
118
|
+
@style = @helper.parameter_specified?('style')
|
106
119
|
|
107
120
|
# If a label was specified, use it, otherwise concatenate any dangling parameters and use that as the label
|
108
|
-
@label ||= @helper.params.join(
|
121
|
+
@label ||= @helper.params.join(' ')
|
109
122
|
|
110
123
|
@logger.debug { "@make_copy_button = '#{@make_copy_button}'; @label = '#{@label}'" }
|
111
|
-
PreTagBlock.make_pre(@make_copy_button, @number_lines, @label, @dark, @highlight, content)
|
124
|
+
PreTagBlock.make_pre(@make_copy_button, @number_lines, @label, @dark, @highlight, @class, @style, @clear, content)
|
112
125
|
end
|
113
126
|
end
|
114
127
|
|
@@ -124,7 +137,7 @@ class UnselectableTag < Liquid::Tag
|
|
124
137
|
@logger = PluginMetaLogger.instance.new_logger(self)
|
125
138
|
|
126
139
|
@markup = markup
|
127
|
-
@markup =
|
140
|
+
@markup = '$ ' if @markup.nil? || @markup.empty?
|
128
141
|
@logger.debug { "UnselectableTag: markup= '#{@markup}'" }
|
129
142
|
end
|
130
143
|
|
@@ -134,5 +147,5 @@ class UnselectableTag < Liquid::Tag
|
|
134
147
|
end
|
135
148
|
|
136
149
|
PluginMetaLogger.instance.info { "Loaded #{JekyllPluginPreName::PLUGIN_NAME} v#{JekyllPreVersion::VERSION} plugin." }
|
137
|
-
Liquid::Template.register_tag(
|
138
|
-
Liquid::Template.register_tag(
|
150
|
+
Liquid::Template.register_tag('pre', PreTagBlock)
|
151
|
+
Liquid::Template.register_tag('noselect', UnselectableTag)
|
data/lib/jekyll_tag_helper.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'shellwords'
|
4
4
|
require 'key_value_parser'
|
5
5
|
|
6
|
+
# Parses arguments and options
|
6
7
|
class JekyllTagHelper
|
7
8
|
attr_reader :argv, :liquid_context, :logger, :params, :tag_name
|
8
9
|
|
9
10
|
def self.escape_html(string)
|
10
|
-
string.gsub(
|
11
|
-
.gsub(
|
12
|
-
.gsub(
|
13
|
-
.gsub(
|
11
|
+
string.gsub('&', '&')
|
12
|
+
.gsub('{', '{')
|
13
|
+
.gsub('}', '}')
|
14
|
+
.gsub('<', '<')
|
14
15
|
end
|
15
16
|
|
16
17
|
# Expand a environment variable reference
|
17
|
-
def self.expand_env(str, die_if_undefined
|
18
|
+
def self.expand_env(str, die_if_undefined: false)
|
18
19
|
str.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do
|
19
20
|
envar = Regexp.last_match(1)
|
20
21
|
raise FlexibleError, "flexible_include error: #{envar} is undefined".red, [] if !ENV.key?(envar) && die_if_undefined # Suppress stack trace
|
22
|
+
|
21
23
|
ENV[envar]
|
22
24
|
end
|
23
25
|
end
|
@@ -67,7 +69,7 @@ class JekyllTagHelper
|
|
67
69
|
value = @liquid_context[name] # Finds variables named like 'include.my_variable', found in @liquid_context.scopes.first
|
68
70
|
value ||= @page[name] if @page # Finds variables named like 'page.my_variable'
|
69
71
|
value ||= dereference_include_variable(name)
|
70
|
-
value ||=
|
72
|
+
value ||= ''
|
71
73
|
value
|
72
74
|
end
|
73
75
|
|
@@ -79,9 +81,9 @@ class JekyllTagHelper
|
|
79
81
|
|
80
82
|
def lookup_variable(symbol)
|
81
83
|
string = symbol.to_s
|
82
|
-
return string unless string.start_with?(
|
84
|
+
return string unless string.start_with?('{{') && string.end_with?('}}')
|
83
85
|
|
84
|
-
dereference_variable(string.delete_prefix(
|
86
|
+
dereference_variable(string.delete_prefix('{{').delete_suffix('}}'))
|
85
87
|
end
|
86
88
|
|
87
89
|
def page
|
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.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Slinn
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04
|
11
|
+
date: 2022-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -66,38 +66,10 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: debase
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: ruby-debug-ide
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
69
|
description: 'Jekyll tags pre and noselect, for HTML <pre/> tag, prompts and unselectable
|
98
70
|
text. Can number lines.
|
99
71
|
|
100
|
-
'
|
72
|
+
'
|
101
73
|
email:
|
102
74
|
- mslinn@mslinn.com
|
103
75
|
executables: []
|
@@ -143,8 +115,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
115
|
- !ruby/object:Gem::Version
|
144
116
|
version: '0'
|
145
117
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
118
|
+
rubygems_version: 3.3.3
|
119
|
+
signing_key:
|
148
120
|
specification_version: 4
|
149
121
|
summary: Jekyll tags pre and noselect, for HTML <pre/> tag, prompts and unselectable
|
150
122
|
text. Can number lines.
|
@@ -152,3 +124,4 @@ test_files:
|
|
152
124
|
- spec/pre_spec.rb
|
153
125
|
- spec/spec_helper.rb
|
154
126
|
- spec/status_persistence.txt
|
127
|
+
...
|