jekyll-antex 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll/antex.rb +1 -3
- data/lib/jekyll/antex/alias.rb +6 -13
- data/lib/jekyll/antex/defaults.yml +22 -28
- data/lib/jekyll/antex/generator.rb +19 -20
- data/lib/jekyll/antex/guard.rb +1 -13
- data/lib/jekyll/antex/options.rb +0 -4
- data/lib/jekyll/antex/stasher.rb +51 -0
- data/lib/jekyll/antex/version.rb +1 -1
- metadata +33 -21
- data/lib/jekyll/antex/dealiaser.rb +0 -63
- data/lib/jekyll/antex/guardian.rb +0 -52
- data/lib/jekyll/antex/utils.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8af04a4d3122b7e58926aed907120b7bef5e4d5cfb660be03c625f1e0ec48d4
|
4
|
+
data.tar.gz: 4066bd201baba8f6bdcf724f38ea8991eb011da58f1da13831d32547781ade9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86ebce737fc0c681b040f329d46aee48198d528a25e0bab5bbbecebc5da5215fb5f462bd385a5f211e97063b45639feaf76cfa0343ac19ec7fd28ccf0091c530
|
7
|
+
data.tar.gz: 381bc28893d16e442f07567eddee15b08bab1eed15387eb4b3793dbc8e35949a61dcaa0d79e98b1716db5268762d99c6e91304c806a81e914eeaaf111658eee3
|
data/lib/jekyll/antex.rb
CHANGED
@@ -4,11 +4,9 @@ require 'antex'
|
|
4
4
|
|
5
5
|
require 'jekyll/antex/version'
|
6
6
|
require 'jekyll/antex/error'
|
7
|
-
require 'jekyll/antex/utils'
|
8
7
|
require 'jekyll/antex/options'
|
9
8
|
require 'jekyll/antex/guard'
|
10
|
-
require 'jekyll/antex/
|
9
|
+
require 'jekyll/antex/stasher'
|
11
10
|
require 'jekyll/antex/alias'
|
12
|
-
require 'jekyll/antex/dealiaser'
|
13
11
|
require 'jekyll/antex/generator'
|
14
12
|
require 'jekyll/antex/block'
|
data/lib/jekyll/antex/alias.rb
CHANGED
@@ -1,31 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'jekyll/antex/error'
|
4
|
-
require 'jekyll/antex/utils'
|
5
4
|
|
6
5
|
module Jekyll
|
7
6
|
module Antex
|
8
|
-
class
|
9
|
-
class InvalidRegexp < Error; end
|
7
|
+
class InvalidRegexp < Error; end
|
10
8
|
|
11
|
-
|
9
|
+
Alias = Struct.new(:priority, :regexp, :options, keyword_init: true) do
|
12
10
|
|
13
|
-
def initialize(
|
14
|
-
|
15
|
-
@priority = priority.to_i
|
16
|
-
@regexp = Utils.build_regexp source: regexp,
|
17
|
-
extended: extended,
|
18
|
-
multiline: multiline
|
11
|
+
def initialize(*args)
|
12
|
+
super
|
19
13
|
validate_regexp!
|
20
|
-
@options = options.to_h
|
21
14
|
end
|
22
15
|
|
23
16
|
private
|
24
17
|
|
25
18
|
def validate_regexp!
|
26
|
-
return if
|
19
|
+
return if regexp.names.include? 'code'
|
27
20
|
raise InvalidRegexp, <<~MESSAGE
|
28
|
-
The regexp #{
|
21
|
+
The regexp #{regexp.inspect} is missing the required named matching group "code".
|
29
22
|
MESSAGE
|
30
23
|
end
|
31
24
|
end
|
@@ -76,45 +76,40 @@ commands:
|
|
76
76
|
guards:
|
77
77
|
comment:
|
78
78
|
priority: 1000
|
79
|
-
|
80
|
-
|
81
|
-
<!---
|
79
|
+
regexp: !ruby/regexp |
|
80
|
+
/<!---
|
82
81
|
.*?
|
83
|
-
|
82
|
+
--->/mx
|
84
83
|
verbatim:
|
85
84
|
priority: 100
|
86
|
-
|
87
|
-
|
88
|
-
```
|
85
|
+
regexp: !ruby/regexp |
|
86
|
+
/```
|
89
87
|
.*?
|
90
|
-
|
88
|
+
```/mx
|
91
89
|
aliases:
|
92
90
|
# 'internal' must have the highest priority;
|
93
91
|
# it is the liquid tag all other aliases are rendered to.
|
94
92
|
internal:
|
95
93
|
priority: 1000
|
96
|
-
|
97
|
-
|
98
|
-
{%\s*antex\s*(?<markup>.*?)%}
|
94
|
+
regexp: !ruby/regexp |
|
95
|
+
/{%\s*antex\s*(?<markup>.*?)%}
|
99
96
|
(?<code>.*?)
|
100
|
-
{%\s*endantex\s*%}
|
97
|
+
{%\s*endantex\s*%}/mx
|
101
98
|
# 'default' is the standard generic purpose alias.
|
102
99
|
# Since it can contain tikz pictures,
|
103
100
|
# it must have higher priority than 'tikzpicture' alias.
|
104
101
|
default:
|
105
102
|
priority: 100
|
106
|
-
|
107
|
-
|
108
|
-
{%\s*tex\s*(?<markup>.*?)%}
|
103
|
+
regexp: !ruby/regexp |
|
104
|
+
/{%\s*tex\s*(?<markup>.*?)%}
|
109
105
|
(?<code>.*?)
|
110
|
-
{%\s*endtex\s*%}
|
106
|
+
{%\s*endtex\s*%}/mx
|
111
107
|
tikzpicture:
|
112
108
|
priority: 90
|
113
|
-
|
114
|
-
|
115
|
-
{%\s*tikz\s*(?<markup>.*?)%}
|
109
|
+
regexp: !ruby/regexp |
|
110
|
+
/{%\s*tikz\s*(?<markup>.*?)%}
|
116
111
|
(?<code>.*?)
|
117
|
-
{%\s*endtikz\s*%}
|
112
|
+
{%\s*endtikz\s*%}/mx
|
118
113
|
options:
|
119
114
|
prepend: '\\begin{tikzpicture}'
|
120
115
|
append: '\\end{tikzpicture}'
|
@@ -123,19 +118,18 @@ aliases:
|
|
123
118
|
# since the respective deliniters are double and single dollars.
|
124
119
|
display_math:
|
125
120
|
priority: 20
|
126
|
-
|
127
|
-
|
128
|
-
\$\$
|
121
|
+
regexp: !ruby/regexp |
|
122
|
+
/\$\$
|
129
123
|
(?<code>.*?)
|
130
|
-
|
124
|
+
\$\$/mx
|
131
125
|
options:
|
132
126
|
prepend: '$\\displaystyle'
|
133
127
|
append: $
|
134
128
|
classes: [antex, display]
|
135
129
|
inline_math:
|
136
130
|
priority: 10
|
137
|
-
regexp:
|
138
|
-
|
131
|
+
regexp: !ruby/regexp |
|
132
|
+
/\$(?<code>.*?)\$/x
|
139
133
|
options:
|
140
134
|
prepend: $
|
141
135
|
append: $
|
@@ -144,7 +138,7 @@ aliases:
|
|
144
138
|
# to avoid interference with others aliases.
|
145
139
|
inline_macro:
|
146
140
|
priority: 0
|
147
|
-
regexp:
|
148
|
-
(?<code>\\[A-z]+)
|
141
|
+
regexp: !ruby/regexp |
|
142
|
+
/(?<code>\\[A-z]+)/x
|
149
143
|
options:
|
150
144
|
classes: [antex, inline]
|
@@ -4,10 +4,12 @@ require 'jekyll'
|
|
4
4
|
require 'jekyll/utils'
|
5
5
|
|
6
6
|
require 'jekyll/antex/alias'
|
7
|
-
require 'jekyll/antex/dealiaser'
|
8
|
-
|
9
7
|
require 'jekyll/antex/guard'
|
10
|
-
require 'jekyll/antex/
|
8
|
+
require 'jekyll/antex/stasher'
|
9
|
+
require 'jekyll/antex/options'
|
10
|
+
|
11
|
+
# NOTE: I'm pretty conflicted about this.
|
12
|
+
SafeYAML::OPTIONS[:whitelisted_tags].push('!ruby/regexp')
|
11
13
|
|
12
14
|
module Jekyll
|
13
15
|
module Antex
|
@@ -27,11 +29,13 @@ module Jekyll
|
|
27
29
|
|
28
30
|
def dealias_resource_content!(site:, resource:)
|
29
31
|
options = build_options site: site, resource: resource
|
30
|
-
guardian =
|
31
|
-
dealiaser =
|
32
|
-
resource.content = guardian.
|
33
|
-
resource.content = dealiaser.
|
34
|
-
|
32
|
+
guardian = Jekyll::Antex::Stasher.new(build_guards(options['guards']))
|
33
|
+
dealiaser = Jekyll::Antex::Stasher.new(build_aliases(options['aliases']))
|
34
|
+
resource.content = guardian.lift(resource.content)
|
35
|
+
resource.content = dealiaser.lift(resource.content)
|
36
|
+
dealiaser.bake(&self.class.method(:dealias_tag))
|
37
|
+
resource.content = dealiaser.drop(resource.content)
|
38
|
+
resource.content = guardian.drop(resource.content)
|
35
39
|
end
|
36
40
|
|
37
41
|
def build_options(site:, resource:)
|
@@ -40,18 +44,6 @@ module Jekyll
|
|
40
44
|
resource.data['antex'] || {}
|
41
45
|
end
|
42
46
|
|
43
|
-
def build_guardian(guards_options_hash)
|
44
|
-
guardian = Jekyll::Antex::Guardian.new
|
45
|
-
guardian.add_guards build_guards(guards_options_hash)
|
46
|
-
guardian
|
47
|
-
end
|
48
|
-
|
49
|
-
def build_dealiaser(aliases_options_hash)
|
50
|
-
dealiaser = Jekyll::Antex::Dealiaser.new
|
51
|
-
dealiaser.add_aliases build_aliases(aliases_options_hash)
|
52
|
-
dealiaser
|
53
|
-
end
|
54
|
-
|
55
47
|
def build_guards(options_hash)
|
56
48
|
options_hash.values.map do |args|
|
57
49
|
Guard.new Jekyll::Utils.symbolize_hash_keys(args)
|
@@ -63,6 +55,13 @@ module Jekyll
|
|
63
55
|
Alias.new Jekyll::Utils.symbolize_hash_keys(args)
|
64
56
|
end
|
65
57
|
end
|
58
|
+
|
59
|
+
def self.dealias_tag(match, matcher)
|
60
|
+
markup = YAML.safe_load match[:markup] if match.names.include?('markup')
|
61
|
+
markup = YAML.dump Options.build(matcher.options || {}, markup || {})
|
62
|
+
code = match['code']
|
63
|
+
"{% antex #{markup} %}#{code}{% endantex %}"
|
64
|
+
end
|
66
65
|
end
|
67
66
|
end
|
68
67
|
end
|
data/lib/jekyll/antex/guard.rb
CHANGED
@@ -1,19 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'jekyll/antex/utils'
|
4
|
-
|
5
3
|
module Jekyll
|
6
4
|
module Antex
|
7
|
-
|
8
|
-
attr_reader :priority, :regexp
|
9
|
-
|
10
|
-
def initialize(priority:, regexp:,
|
11
|
-
multiline: false, extended: true)
|
12
|
-
@priority = priority.to_i
|
13
|
-
@regexp = Utils.build_regexp source: regexp,
|
14
|
-
extended: extended,
|
15
|
-
multiline: multiline
|
16
|
-
end
|
17
|
-
end
|
5
|
+
Guard = Struct.new(:priority, :regexp, keyword_init: true)
|
18
6
|
end
|
19
7
|
end
|
data/lib/jekyll/antex/options.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Antex
|
7
|
+
class Stasher
|
8
|
+
attr_reader :matchers
|
9
|
+
|
10
|
+
def initialize(matchers)
|
11
|
+
@stash = []
|
12
|
+
@matchers = matchers
|
13
|
+
@matchers.sort_by!(&:priority)
|
14
|
+
@matchers.reverse!
|
15
|
+
end
|
16
|
+
|
17
|
+
def lift(input)
|
18
|
+
input.dup.tap do |output|
|
19
|
+
@matchers.each do |matcher|
|
20
|
+
output.gsub!(matcher.regexp) do
|
21
|
+
store(Regexp.last_match, matcher)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def bake
|
28
|
+
@stash.map! do |uuid, match, matcher|
|
29
|
+
replacement = yield match, matcher
|
30
|
+
[uuid, match, matcher, replacement]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def drop(input)
|
35
|
+
input.dup.tap do |output|
|
36
|
+
@stash.each do |uuid, match, _, replacement|
|
37
|
+
output.gsub!(uuid) { replacement || match.to_s }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def store(match, matcher)
|
45
|
+
SecureRandom.uuid.tap do |uuid|
|
46
|
+
@stash.push([uuid, match, matcher, nil])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/jekyll/antex/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-antex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paolo Brasolin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.8'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3.
|
26
|
+
version: '3.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: antex
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,84 +44,98 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '10'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '10'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: guard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '2
|
61
|
+
version: '2'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '2
|
68
|
+
version: '2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: guard-rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '4
|
75
|
+
version: '4'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '4
|
82
|
+
version: '4'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: reek
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '4'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '4'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '3
|
103
|
+
version: '3'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '3
|
110
|
+
version: '3'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rubocop
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0.
|
117
|
+
version: '0.52'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.52'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.16'
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0.
|
138
|
+
version: '0.16'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: yard
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -148,14 +162,12 @@ files:
|
|
148
162
|
- lib/jekyll/antex.rb
|
149
163
|
- lib/jekyll/antex/alias.rb
|
150
164
|
- lib/jekyll/antex/block.rb
|
151
|
-
- lib/jekyll/antex/dealiaser.rb
|
152
165
|
- lib/jekyll/antex/defaults.yml
|
153
166
|
- lib/jekyll/antex/error.rb
|
154
167
|
- lib/jekyll/antex/generator.rb
|
155
168
|
- lib/jekyll/antex/guard.rb
|
156
|
-
- lib/jekyll/antex/guardian.rb
|
157
169
|
- lib/jekyll/antex/options.rb
|
158
|
-
- lib/jekyll/antex/
|
170
|
+
- lib/jekyll/antex/stasher.rb
|
159
171
|
- lib/jekyll/antex/version.rb
|
160
172
|
homepage: https://github.com/paolobrasolin/antex
|
161
173
|
licenses:
|
@@ -169,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
169
181
|
requirements:
|
170
182
|
- - ">="
|
171
183
|
- !ruby/object:Gem::Version
|
172
|
-
version: '2.
|
184
|
+
version: '2.5'
|
173
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
186
|
requirements:
|
175
187
|
- - ">="
|
@@ -1,63 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'securerandom'
|
4
|
-
|
5
|
-
require 'jekyll/antex/options'
|
6
|
-
|
7
|
-
module Jekyll
|
8
|
-
module Antex
|
9
|
-
class Dealiaser
|
10
|
-
attr_reader :aliases
|
11
|
-
|
12
|
-
def initialize(tag: 'antex')
|
13
|
-
@aliases = []
|
14
|
-
@stash = {}
|
15
|
-
@tag = tag
|
16
|
-
end
|
17
|
-
|
18
|
-
def add_aliases(aliases)
|
19
|
-
@aliases.concat(aliases).sort_by!(&:priority).reverse!
|
20
|
-
end
|
21
|
-
|
22
|
-
def parse(content)
|
23
|
-
@content = content.dup
|
24
|
-
@stash = {}
|
25
|
-
stash_aliases
|
26
|
-
render_stashed_aliases_as_tags
|
27
|
-
unstash_tags
|
28
|
-
@content
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def stash_aliases
|
34
|
-
@aliases.each do |aliaz|
|
35
|
-
@content.gsub!(aliaz.regexp) do
|
36
|
-
uuid = SecureRandom.uuid
|
37
|
-
@stash.store uuid, match: Regexp.last_match, options: aliaz.options
|
38
|
-
uuid
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def render_stashed_aliases_as_tags
|
44
|
-
@stash.each do |key, value|
|
45
|
-
@stash[key] = render_matched_alias_as_tag(**value)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def unstash_tags
|
50
|
-
@stash.each do |uuid, rendered_tag|
|
51
|
-
@content.gsub!(uuid) { rendered_tag }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def render_matched_alias_as_tag(match:, options:)
|
56
|
-
markup = YAML.safe_load match[:markup] if match.names.include?('markup')
|
57
|
-
markup = YAML.dump Options.build(options || {}, markup || {})
|
58
|
-
code = match['code']
|
59
|
-
"{% #{@tag} #{markup} %}#{code}{% end#{@tag} %}"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'securerandom'
|
4
|
-
|
5
|
-
module Jekyll
|
6
|
-
module Antex
|
7
|
-
class Guardian
|
8
|
-
attr_reader :guards
|
9
|
-
|
10
|
-
def initialize(tag: 'antex')
|
11
|
-
@guards = []
|
12
|
-
@stash = {}
|
13
|
-
@tag = tag
|
14
|
-
end
|
15
|
-
|
16
|
-
def add_guards(guards)
|
17
|
-
@guards.concat(guards).sort_by!(&:priority).reverse!
|
18
|
-
end
|
19
|
-
|
20
|
-
def apply(content)
|
21
|
-
@content = content.dup
|
22
|
-
@stash = {}
|
23
|
-
stash_guards
|
24
|
-
@content
|
25
|
-
end
|
26
|
-
|
27
|
-
def remove(content)
|
28
|
-
@content = content.dup
|
29
|
-
unstash_guards
|
30
|
-
@content
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def stash_guards
|
36
|
-
@guards.each do |guard|
|
37
|
-
@content.gsub!(guard.regexp) do
|
38
|
-
uuid = SecureRandom.uuid
|
39
|
-
@stash.store uuid, Regexp.last_match.to_s
|
40
|
-
uuid
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def unstash_guards
|
46
|
-
@stash.each do |uuid, guard_match|
|
47
|
-
@content.gsub!(uuid) { guard_match }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
data/lib/jekyll/antex/utils.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
module Antex
|
5
|
-
module Utils
|
6
|
-
def self.build_regexp(source:, extended:, multiline:)
|
7
|
-
options = 0
|
8
|
-
options |= Regexp::EXTENDED if extended
|
9
|
-
options |= Regexp::MULTILINE if multiline
|
10
|
-
Regexp.new source, options
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|