jekyll-highlight-param 0.0.1 → 0.0.2
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/.ruby-version +1 -0
- data/README.md +113 -0
- data/lib/jekyll-highlight-param.rb +81 -22
- data/lib/jekyll/tags/include.rb +270 -0
- data/lib/jekyll/tags/link.rb +42 -0
- metadata +7 -5
- data/jekyll-highlight-param.gemspec +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee62e924028e4852ec50e55d532ee86339f7794e676126ec21abee8853277d47
|
4
|
+
data.tar.gz: '08ab4c9ec59a4742f367e929d59c7d59575599b477377cf7937cfb0ff88cc700'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5c1ca294060894d593b72e3e2aa544972ea2cb7f6cdf9df0b2564069d52f50f42cdeeb77c81f77f00656ae7750282cc29e4278931576c698fda3e19e72e5a38
|
7
|
+
data.tar.gz: c1e99c02e6f95d9c226e903be96f7ec1a265f0a522eb85ba918f9cc55554a7d6b2844ef5172cf769a0ef041b53fe175cc0f9e126d9c42d83ece53ce548faec19
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.6
|
data/README.md
CHANGED
@@ -1 +1,114 @@
|
|
1
1
|
# jekyll-highlight-param
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/jekyll-highlight-param)
|
4
|
+
|
5
|
+
A Liquid tag plugin for Jekyll that replaces the built in `{% highlight %}` tag, and allows passing the language to highlight in as a parameter.
|
6
|
+
|
7
|
+
_An issue for making this change a part of the mainline Jekyll Highlight tag can be found [here](https://github.com/jekyll/jekyll/issues/8290)._
|
8
|
+
|
9
|
+
_**It appears v0.0.1 did not actually work as intended, and was simply failing gracefully by detecting the language from the code itself. A better job of detecting errors and alerting the user was devised in v0.0.2.**_
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
group :jekyll_plugins do
|
17
|
+
gem 'jekyll-highlight-param', :github => 'UriShX/jekyll-highlight-param'
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install jekyll-highlight-param
|
28
|
+
|
29
|
+
Then add the following to your site's `_config.yml`:
|
30
|
+
|
31
|
+
```yaml
|
32
|
+
plugins:
|
33
|
+
- jekyll-highlight-param
|
34
|
+
```
|
35
|
+
|
36
|
+
💡 If you are using a Jekyll version less than 3.5.0, use the `gems` key instead of `plugins`.
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
### Basic usage
|
41
|
+
Basic usage is the same as Jekyll's `{% highlight %}` tag, i.e.:
|
42
|
+
|
43
|
+
```liquid
|
44
|
+
{% highlight_param ruby %}
|
45
|
+
def foo
|
46
|
+
puts 'foo'
|
47
|
+
end
|
48
|
+
{% endhighlight_param %}
|
49
|
+
```
|
50
|
+
|
51
|
+
### Using variables names for the language
|
52
|
+
|
53
|
+
_Please note: Since v0.0.2 passing variables to the `highlight_param` tag is done in a similar way to the syntax for passing variables to other tags, such as `link`. This is a breaking change from v0.0.1._
|
54
|
+
|
55
|
+
The name of the language you for the code to be highlighted can be specified as a variable instead of specifying the language directly in the template. For example, suppose you defined a variable in your page's front matter like this:
|
56
|
+
|
57
|
+
```yaml
|
58
|
+
---
|
59
|
+
title: My page
|
60
|
+
my_code: footer_company_a.html
|
61
|
+
my_lang: liquid
|
62
|
+
---
|
63
|
+
```
|
64
|
+
|
65
|
+
You could then reference that variable in your highlight:
|
66
|
+
|
67
|
+
```liquid
|
68
|
+
{% if page.my_variable %}
|
69
|
+
{% capture my_code %}
|
70
|
+
{% include {{ page.code }} %}
|
71
|
+
{% endcapture %}
|
72
|
+
{% highlight_param {{ page.my_lang }} %}
|
73
|
+
{{ my_code | strip }}
|
74
|
+
{% endhighlight_param %}
|
75
|
+
{% endif %}
|
76
|
+
```
|
77
|
+
|
78
|
+
In this example, the capture will store the include file `_includes/footer_company_a.html`, then the highlight will would match the display to match the syntax of `liquid`.
|
79
|
+
|
80
|
+
### Line numbers
|
81
|
+
|
82
|
+
You could also pass a line numbers argument, as in the original `{% highlight %}` tag, both as parameter and as a variable. Line numbers are enabled when passing the `linenos` argument, and disabled as default.
|
83
|
+
|
84
|
+
```liquid
|
85
|
+
{% highlight_param ruby linenos %}
|
86
|
+
def foo
|
87
|
+
puts 'foo'
|
88
|
+
end
|
89
|
+
{% endhighlight_param %}
|
90
|
+
```
|
91
|
+
or:
|
92
|
+
|
93
|
+
```yaml
|
94
|
+
---
|
95
|
+
title: My page
|
96
|
+
line_numbers: linenos
|
97
|
+
---
|
98
|
+
```
|
99
|
+
|
100
|
+
```liquid
|
101
|
+
{% highlight_param ruby {{ page.line_numbers }} %}
|
102
|
+
def foo
|
103
|
+
puts 'foo'
|
104
|
+
end
|
105
|
+
{% endhighlight_param %}
|
106
|
+
```
|
107
|
+
|
108
|
+
## Contributing
|
109
|
+
|
110
|
+
1. Fork it.
|
111
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
112
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
113
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
114
|
+
5. Create a new Pull Request
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require "rouge"
|
3
2
|
|
4
3
|
module Jekyll
|
5
4
|
module Tags
|
@@ -11,20 +10,55 @@ module Jekyll
|
|
11
10
|
# forms: name, name=value, or name="<quoted list>"
|
12
11
|
#
|
13
12
|
# <quoted list> is a space-separated list of numbers
|
14
|
-
|
13
|
+
#
|
14
|
+
# Both the language specifier and the options can be passed as liquid variables,
|
15
|
+
# please consult the documentation at https://github.com/UriShX/jekyll-highlight-param/blob/master/README.md#usage.
|
16
|
+
PARAM_SYNTAX = %r!(\w+([.]\w+)*)!x.freeze
|
17
|
+
LANG_SYNTAX = %r!([a-zA-Z0-9.+#_-]+)!x.freeze
|
18
|
+
OPTIONS_SYNTAX = %r!(\s+\w+(=(\w+|"([0-9]+\s)*[0-9]+")?)*)!.freeze
|
19
|
+
VARIABLE_SYNTAX = %r!
|
20
|
+
^(
|
21
|
+
\{\{\s*
|
22
|
+
(?<lang_var>#{PARAM_SYNTAX})
|
23
|
+
\s*\}\}|
|
24
|
+
(?<lang>#{LANG_SYNTAX})
|
25
|
+
)
|
26
|
+
\s*
|
27
|
+
((?<fault1>[}]+\s*|)
|
28
|
+
(
|
29
|
+
\{\{\s*
|
30
|
+
(?<params_var>(#{PARAM_SYNTAX}))
|
31
|
+
\s*\}\}|
|
32
|
+
(?<params>(#{OPTIONS_SYNTAX}+))
|
33
|
+
)
|
34
|
+
(?<fault2>.*))?
|
35
|
+
!mx.freeze
|
36
|
+
|
37
|
+
def isNilOrEmpty(var)
|
38
|
+
if var.nil?
|
39
|
+
return true
|
40
|
+
elsif var.strip.empty?
|
41
|
+
return true
|
42
|
+
else
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
end
|
15
46
|
|
16
47
|
def initialize(tag_name, markup, tokens)
|
17
48
|
super
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
49
|
+
markup = markup.strip
|
50
|
+
@matched = markup.match(VARIABLE_SYNTAX)
|
51
|
+
# print @matched.captures.to_s + "\n"
|
52
|
+
if !@matched or !isNilOrEmpty(@matched["fault1"]) or !isNilOrEmpty(@matched["fault2"])
|
22
53
|
raise SyntaxError, <<~MSG
|
23
|
-
Syntax Error in tag '
|
54
|
+
Syntax Error in tag '#{tag_name}' while parsing the following markup:
|
24
55
|
|
25
56
|
#{markup}
|
26
57
|
|
27
|
-
Valid syntax:
|
58
|
+
Valid syntax: #{tag_name} <lang> [linenos]
|
59
|
+
\tOR: #{tag_name} {{ lang_variable }} [linenos]
|
60
|
+
\tOR: #{tag_name} <lang> {{ [linenos_variable(s)] }}
|
61
|
+
\tOR: #{tag_name} {{ lang_variable }} {{ [linenos_variable(s)] }}
|
28
62
|
MSG
|
29
63
|
end
|
30
64
|
end
|
@@ -36,18 +70,36 @@ module Jekyll
|
|
36
70
|
suffix = context["highlighter_suffix"] || ""
|
37
71
|
code = super.to_s.gsub(LEADING_OR_TRAILING_LINE_TERMINATORS, "")
|
38
72
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
73
|
+
if @matched["lang_var"]
|
74
|
+
@lang = context[@matched["lang_var"]].downcase
|
75
|
+
@lang.match(LANG_SYNTAX)
|
76
|
+
unless $& == @lang
|
77
|
+
raise ArgumentError, <<~MSG
|
78
|
+
Language characters can only include Alphanumeric and the following characters, without spaces: . + # _ -
|
79
|
+
Your passed language variable: #{@lang}
|
80
|
+
MSG
|
81
|
+
end
|
82
|
+
elsif @matched["lang"]
|
83
|
+
@lang = @matched["lang"].downcase
|
84
|
+
else
|
85
|
+
raise SyntaxError, <<~MSG
|
86
|
+
Unknown Syntax Error in tag 'highlight_param'.
|
87
|
+
Please review tag documentation.
|
88
|
+
MSG
|
48
89
|
end
|
49
|
-
|
50
|
-
|
90
|
+
|
91
|
+
# puts @lang
|
92
|
+
|
93
|
+
if @matched["params_var"]
|
94
|
+
@highlight_options = parse_options(@matched["params_var"])
|
95
|
+
elsif @matched["params"]
|
96
|
+
@highlight_options = parse_options(@matched["params"])
|
97
|
+
else
|
98
|
+
@highlight_options = parse_options("")
|
99
|
+
end
|
100
|
+
|
101
|
+
# puts @highlight_options
|
102
|
+
|
51
103
|
output =
|
52
104
|
case context.registers[:site].highlighter
|
53
105
|
when "rouge"
|
@@ -68,7 +120,7 @@ module Jekyll
|
|
68
120
|
|
69
121
|
def parse_options(input)
|
70
122
|
options = {}
|
71
|
-
return options if input
|
123
|
+
return options if isNilOrEmpty(input)
|
72
124
|
|
73
125
|
# Split along 3 possible forms -- key="<quoted list>", key=value, or key
|
74
126
|
input.scan(OPTIONS_REGEX) do |opt|
|
@@ -92,6 +144,7 @@ module Jekyll
|
|
92
144
|
end
|
93
145
|
|
94
146
|
def render_rouge(code)
|
147
|
+
require "rouge"
|
95
148
|
formatter = ::Rouge::Formatters::HTMLLegacy.new(
|
96
149
|
:line_numbers => @highlight_options[:linenos],
|
97
150
|
:wrap => false,
|
@@ -99,7 +152,13 @@ module Jekyll
|
|
99
152
|
:gutter_class => "gutter",
|
100
153
|
:code_class => "code"
|
101
154
|
)
|
102
|
-
|
155
|
+
if LANG_SYNTAX.match?(@lang)
|
156
|
+
lexer = ::Rouge::Lexer.find_fancy(@lang, code) || Rouge::Lexers::PlainText
|
157
|
+
else
|
158
|
+
raise SyntaxError, <<~MSG
|
159
|
+
Can't find language variable #{@matched["lang_var"]}
|
160
|
+
MSG
|
161
|
+
end
|
103
162
|
formatter.format(lexer.lex(code))
|
104
163
|
end
|
105
164
|
|
@@ -119,4 +178,4 @@ module Jekyll
|
|
119
178
|
end
|
120
179
|
end
|
121
180
|
|
122
|
-
Liquid::Template.register_tag("highlight_param", Jekyll::Tags::HighlightBlockParam)
|
181
|
+
Liquid::Template.register_tag("highlight_param", Jekyll::Tags::HighlightBlockParam)
|
@@ -0,0 +1,270 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Tags
|
5
|
+
class IncludeTag < Liquid::Tag
|
6
|
+
VALID_SYNTAX = %r!
|
7
|
+
([\w-]+)\s*=\s*
|
8
|
+
(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w.-]+))
|
9
|
+
!x.freeze
|
10
|
+
VARIABLE_SYNTAX = %r!
|
11
|
+
(?<variable>[^{]*(\{\{\s*[\w\-.]+\s*(\|.*)?\}\}[^\s{}]*)+)
|
12
|
+
(?<params>.*)
|
13
|
+
!mx.freeze
|
14
|
+
|
15
|
+
FULL_VALID_SYNTAX = %r!\A\s*(?:#{VALID_SYNTAX}(?=\s|\z)\s*)*\z!.freeze
|
16
|
+
VALID_FILENAME_CHARS = %r!^[\w/.-]+$!.freeze
|
17
|
+
INVALID_SEQUENCES = %r![./]{2,}!.freeze
|
18
|
+
|
19
|
+
def initialize(tag_name, markup, tokens)
|
20
|
+
super
|
21
|
+
markup = markup.strip
|
22
|
+
matched = markup.match(VARIABLE_SYNTAX)
|
23
|
+
if matched
|
24
|
+
@file = matched["variable"].strip
|
25
|
+
@params = matched["params"].strip
|
26
|
+
else
|
27
|
+
@file, @params = markup.split(%r!\s+!, 2)
|
28
|
+
end
|
29
|
+
validate_params if @params
|
30
|
+
@tag_name = tag_name
|
31
|
+
end
|
32
|
+
|
33
|
+
def syntax_example
|
34
|
+
"{% #{@tag_name} file.ext param='value' param2='value' %}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def parse_params(context)
|
38
|
+
params = {}
|
39
|
+
@params.scan(VALID_SYNTAX) do |key, d_quoted, s_quoted, variable|
|
40
|
+
value = if d_quoted
|
41
|
+
d_quoted.include?('\\"') ? d_quoted.gsub('\\"', '"') : d_quoted
|
42
|
+
elsif s_quoted
|
43
|
+
s_quoted.include?("\\'") ? s_quoted.gsub("\\'", "'") : s_quoted
|
44
|
+
elsif variable
|
45
|
+
context[variable]
|
46
|
+
end
|
47
|
+
|
48
|
+
params[key] = value
|
49
|
+
end
|
50
|
+
params
|
51
|
+
end
|
52
|
+
|
53
|
+
def validate_file_name(file)
|
54
|
+
if INVALID_SEQUENCES.match?(file) || !VALID_FILENAME_CHARS.match?(file)
|
55
|
+
raise ArgumentError, <<~MSG
|
56
|
+
Invalid syntax for include tag. File contains invalid characters or sequences:
|
57
|
+
|
58
|
+
#{file}
|
59
|
+
|
60
|
+
Valid syntax:
|
61
|
+
|
62
|
+
#{syntax_example}
|
63
|
+
|
64
|
+
MSG
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def validate_params
|
69
|
+
unless FULL_VALID_SYNTAX.match?(@params)
|
70
|
+
raise ArgumentError, <<~MSG
|
71
|
+
Invalid syntax for include tag:
|
72
|
+
|
73
|
+
#{@params}
|
74
|
+
|
75
|
+
Valid syntax:
|
76
|
+
|
77
|
+
#{syntax_example}
|
78
|
+
|
79
|
+
MSG
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Grab file read opts in the context
|
84
|
+
def file_read_opts(context)
|
85
|
+
context.registers[:site].file_read_opts
|
86
|
+
end
|
87
|
+
|
88
|
+
# Render the variable if required
|
89
|
+
def render_variable(context)
|
90
|
+
Liquid::Template.parse(@file).render(context) if VARIABLE_SYNTAX.match?(@file)
|
91
|
+
end
|
92
|
+
|
93
|
+
def tag_includes_dirs(context)
|
94
|
+
context.registers[:site].includes_load_paths.freeze
|
95
|
+
end
|
96
|
+
|
97
|
+
def locate_include_file(context, file, safe)
|
98
|
+
includes_dirs = tag_includes_dirs(context)
|
99
|
+
includes_dirs.each do |dir|
|
100
|
+
path = PathManager.join(dir, file)
|
101
|
+
return path if valid_include_file?(path, dir.to_s, safe)
|
102
|
+
end
|
103
|
+
raise IOError, could_not_locate_message(file, includes_dirs, safe)
|
104
|
+
end
|
105
|
+
|
106
|
+
def render(context)
|
107
|
+
site = context.registers[:site]
|
108
|
+
|
109
|
+
file = render_variable(context) || @file
|
110
|
+
validate_file_name(file)
|
111
|
+
|
112
|
+
path = locate_include_file(context, file, site.safe)
|
113
|
+
return unless path
|
114
|
+
|
115
|
+
add_include_to_dependency(site, path, context)
|
116
|
+
|
117
|
+
partial = load_cached_partial(path, context)
|
118
|
+
|
119
|
+
context.stack do
|
120
|
+
context["include"] = parse_params(context) if @params
|
121
|
+
begin
|
122
|
+
partial.render!(context)
|
123
|
+
rescue Liquid::Error => e
|
124
|
+
e.template_name = path
|
125
|
+
e.markup_context = "included " if e.markup_context.nil?
|
126
|
+
raise e
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def add_include_to_dependency(site, path, context)
|
132
|
+
if context.registers[:page]&.key?("path")
|
133
|
+
site.regenerator.add_dependency(
|
134
|
+
site.in_source_dir(context.registers[:page]["path"]),
|
135
|
+
path
|
136
|
+
)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def load_cached_partial(path, context)
|
141
|
+
context.registers[:cached_partials] ||= {}
|
142
|
+
cached_partial = context.registers[:cached_partials]
|
143
|
+
|
144
|
+
if cached_partial.key?(path)
|
145
|
+
cached_partial[path]
|
146
|
+
else
|
147
|
+
unparsed_file = context.registers[:site]
|
148
|
+
.liquid_renderer
|
149
|
+
.file(path)
|
150
|
+
begin
|
151
|
+
cached_partial[path] = unparsed_file.parse(read_file(path, context))
|
152
|
+
rescue Liquid::Error => e
|
153
|
+
e.template_name = path
|
154
|
+
e.markup_context = "included " if e.markup_context.nil?
|
155
|
+
raise e
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def valid_include_file?(path, dir, safe)
|
161
|
+
!outside_site_source?(path, dir, safe) && File.file?(path)
|
162
|
+
end
|
163
|
+
|
164
|
+
def outside_site_source?(path, dir, safe)
|
165
|
+
safe && !realpath_prefixed_with?(path, dir)
|
166
|
+
end
|
167
|
+
|
168
|
+
def realpath_prefixed_with?(path, dir)
|
169
|
+
File.exist?(path) && File.realpath(path).start_with?(dir)
|
170
|
+
rescue StandardError
|
171
|
+
false
|
172
|
+
end
|
173
|
+
|
174
|
+
# This method allows to modify the file content by inheriting from the class.
|
175
|
+
def read_file(file, context)
|
176
|
+
File.read(file, **file_read_opts(context))
|
177
|
+
end
|
178
|
+
|
179
|
+
private
|
180
|
+
|
181
|
+
def could_not_locate_message(file, includes_dirs, safe)
|
182
|
+
message = "Could not locate the included file '#{file}' in any of "\
|
183
|
+
"#{includes_dirs}. Ensure it exists in one of those directories and"
|
184
|
+
message + if safe
|
185
|
+
" is not a symlink as those are not allowed in safe mode."
|
186
|
+
else
|
187
|
+
", if it is a symlink, does not point outside your site source."
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# Do not inherit from this class.
|
193
|
+
# TODO: Merge into the `Jekyll::Tags::IncludeTag` in v5.0
|
194
|
+
class OptimizedIncludeTag < IncludeTag
|
195
|
+
def render(context)
|
196
|
+
@site ||= context.registers[:site]
|
197
|
+
|
198
|
+
file = render_variable(context) || @file
|
199
|
+
validate_file_name(file)
|
200
|
+
|
201
|
+
@site.inclusions[file] ||= locate_include_file(file)
|
202
|
+
inclusion = @site.inclusions[file]
|
203
|
+
|
204
|
+
add_include_to_dependency(inclusion, context) if @site.incremental?
|
205
|
+
|
206
|
+
context.stack do
|
207
|
+
context["include"] = parse_params(context) if @params
|
208
|
+
inclusion.render(context)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
private
|
213
|
+
|
214
|
+
def locate_include_file(file)
|
215
|
+
@site.includes_load_paths.each do |dir|
|
216
|
+
path = PathManager.join(dir, file)
|
217
|
+
return Inclusion.new(@site, dir, file) if valid_include_file?(path, dir)
|
218
|
+
end
|
219
|
+
raise IOError, could_not_locate_message(file, @site.includes_load_paths, @site.safe)
|
220
|
+
end
|
221
|
+
|
222
|
+
def valid_include_file?(path, dir)
|
223
|
+
File.file?(path) && !outside_scope?(path, dir)
|
224
|
+
end
|
225
|
+
|
226
|
+
def outside_scope?(path, dir)
|
227
|
+
@site.safe && !realpath_prefixed_with?(path, dir)
|
228
|
+
end
|
229
|
+
|
230
|
+
def realpath_prefixed_with?(path, dir)
|
231
|
+
File.realpath(path).start_with?(dir)
|
232
|
+
rescue StandardError
|
233
|
+
false
|
234
|
+
end
|
235
|
+
|
236
|
+
def add_include_to_dependency(inclusion, context)
|
237
|
+
return unless context.registers[:page]&.key?("path")
|
238
|
+
|
239
|
+
@site.regenerator.add_dependency(
|
240
|
+
@site.in_source_dir(context.registers[:page]["path"]),
|
241
|
+
inclusion.path
|
242
|
+
)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
class IncludeRelativeTag < IncludeTag
|
247
|
+
def tag_includes_dirs(context)
|
248
|
+
Array(page_path(context)).freeze
|
249
|
+
end
|
250
|
+
|
251
|
+
def page_path(context)
|
252
|
+
page, site = context.registers.values_at(:page, :site)
|
253
|
+
return site.source unless page
|
254
|
+
|
255
|
+
site.in_source_dir File.dirname(resource_path(page, site))
|
256
|
+
end
|
257
|
+
|
258
|
+
private
|
259
|
+
|
260
|
+
def resource_path(page, site)
|
261
|
+
path = page["path"]
|
262
|
+
path = File.join(site.config["collections_dir"], path) if page["collection"]
|
263
|
+
path.sub(%r!/#excerpt\z!, "")
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
Liquid::Template.register_tag("include", Jekyll::Tags::OptimizedIncludeTag)
|
270
|
+
Liquid::Template.register_tag("include_relative", Jekyll::Tags::IncludeRelativeTag)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Tags
|
5
|
+
class Link < Liquid::Tag
|
6
|
+
include Jekyll::Filters::URLFilters
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def tag_name
|
10
|
+
name.split("::").last.downcase
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(tag_name, relative_path, tokens)
|
15
|
+
super
|
16
|
+
|
17
|
+
@relative_path = relative_path.strip
|
18
|
+
end
|
19
|
+
|
20
|
+
def render(context)
|
21
|
+
@context = context
|
22
|
+
site = context.registers[:site]
|
23
|
+
relative_path = Liquid::Template.parse(@relative_path).render(context)
|
24
|
+
relative_path_with_leading_slash = PathManager.join("", relative_path)
|
25
|
+
|
26
|
+
site.each_site_file do |item|
|
27
|
+
return relative_url(item) if item.relative_path == relative_path
|
28
|
+
# This takes care of the case for static files that have a leading /
|
29
|
+
return relative_url(item) if item.relative_path == relative_path_with_leading_slash
|
30
|
+
end
|
31
|
+
|
32
|
+
raise ArgumentError, <<~MSG
|
33
|
+
Could not find document '#{relative_path}' in tag '#{self.class.tag_name}'.
|
34
|
+
|
35
|
+
Make sure the document exists and the path is correct.
|
36
|
+
MSG
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Liquid::Template.register_tag(Jekyll::Tags::Link.tag_name, Jekyll::Tags::Link)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-highlight-param
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uri Shani
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.6'
|
41
41
|
description: A Liquid tag plugin for Jekyll that replaces the built in highlight tag,
|
42
|
-
and allows passing the language to highlight in as a
|
42
|
+
and allows passing the language to highlight in as a liquid variable.
|
43
43
|
email:
|
44
44
|
- usdogi@gmail.com
|
45
45
|
executables: []
|
@@ -47,10 +47,12 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
|
+
- ".ruby-version"
|
50
51
|
- README.md
|
51
|
-
- jekyll-highlight-param.gemspec
|
52
52
|
- lib/jekyll-highlight-param.rb
|
53
|
-
|
53
|
+
- lib/jekyll/tags/include.rb
|
54
|
+
- lib/jekyll/tags/link.rb
|
55
|
+
homepage: https://github.com/urishx/jekyll-highlight-param
|
54
56
|
licenses:
|
55
57
|
- MIT
|
56
58
|
metadata: {}
|
@@ -72,5 +74,5 @@ requirements: []
|
|
72
74
|
rubygems_version: 3.0.3
|
73
75
|
signing_key:
|
74
76
|
specification_version: 4
|
75
|
-
summary: Jekyll syntax highlighter that accepts
|
77
|
+
summary: Jekyll syntax highlighter that accepts variable for the language
|
76
78
|
test_files: []
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
lib = File.expand_path("../lib", __FILE__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "jekyll-highlight-param"
|
8
|
-
spec.version = "0.0.1"
|
9
|
-
spec.date = "2020-09-23"
|
10
|
-
spec.authors = ["Uri Shani"]
|
11
|
-
spec.email = ["usdogi@gmail.com"]
|
12
|
-
spec.summary = "Jekyll syntax highlighter that accepts parameter for the language"
|
13
|
-
spec.description = "A Liquid tag plugin for Jekyll that replaces the built in highlight tag, and allows passing the language to highlight in as a parameter."
|
14
|
-
spec.homepage = "https://github.com/UriShX/jekyll-highlight-param"
|
15
|
-
spec.license = "MIT"
|
16
|
-
spec.required_ruby_version = ">= 2.0.0"
|
17
|
-
|
18
|
-
spec.files = `git ls-files -z`.split("\x0")
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_development_dependency "jekyll", ">= 3.6.3"
|
22
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
-
end
|