jekyll-spaceship 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/jekyll-spaceship/cores/config.rb +14 -0
- data/lib/jekyll-spaceship/cores/manager.rb +5 -0
- data/lib/jekyll-spaceship/cores/processor.rb +50 -1
- data/lib/jekyll-spaceship/processors/mathjax-processor.rb +79 -13
- data/lib/jekyll-spaceship/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 917f5191110c86af367498a90d9ad362185254fdfc30f54eeb48705159b72db7
|
4
|
+
data.tar.gz: 23e627f48d83363b2b473d2c080c98d327ddc51d982290209e218ff755a8920e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daf20ba10a46e6f8538a02b84153bb19f3371e4ea58b689f4c520a04eb7041e76f172ac5886fca2e8a6e9140515fc7afdb30afec97bdda38d99ed43df6ecb3e7
|
7
|
+
data.tar.gz: '089e665d0359d9c0bfe0e37c1e91dfb63c6bc1dacc2c7f928e617c9d3cd1d8af959005a9cc70fca63f05a3ab5c662a24ac2ebaed113073483bc71676146bb12f'
|
data/README.md
CHANGED
@@ -177,8 +177,15 @@ jekyll-spaceship:
|
|
177
177
|
inlineMath:
|
178
178
|
- ['$','$']
|
179
179
|
- ['\(','\)']
|
180
|
+
displayMath:
|
181
|
+
- ['$$','$$']
|
182
|
+
- ['\[','\]']
|
180
183
|
svg:
|
181
184
|
fontCache: 'global'
|
185
|
+
optimize: # optimization on building stage to check and add mathjax scripts
|
186
|
+
enabled: true # value `false` for adding to all pages
|
187
|
+
include: [] # include patterns for math expressions checking (regexp)
|
188
|
+
exclude: [] # exclude patterns for math expressions checking (regexp)
|
182
189
|
plantuml-processor:
|
183
190
|
mode: default # mode value 'pre-fetch' for fetching image at building stage
|
184
191
|
css:
|
@@ -5,6 +5,7 @@ module Jekyll::Spaceship
|
|
5
5
|
CONFIG_NAME = 'jekyll-spaceship'
|
6
6
|
DEFAULT_CONFIG = {
|
7
7
|
'processors' => [
|
8
|
+
'cache-processor',
|
8
9
|
'table-processor',
|
9
10
|
'mathjax-processor',
|
10
11
|
'plantuml-processor',
|
@@ -31,6 +32,16 @@ module Jekyll::Spaceship
|
|
31
32
|
first.merge(second.to_h, &merger)
|
32
33
|
end
|
33
34
|
|
35
|
+
def self.deep_dig(obj, key)
|
36
|
+
if obj.respond_to?(:key?) && obj.key?(key)
|
37
|
+
obj[key]
|
38
|
+
elsif obj.respond_to?(:each)
|
39
|
+
result = nil
|
40
|
+
obj.find { |*a| result = self.deep_dig(a.last, key) }
|
41
|
+
result
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
34
45
|
def self.store(section, default)
|
35
46
|
return @@store[section] if default.nil?
|
36
47
|
@@store[section] = deep_merge(default, @@store[section])
|
@@ -54,7 +65,10 @@ module Jekyll::Spaceship
|
|
54
65
|
def self.load_config
|
55
66
|
# post load site config for `group :jekyll_plugin`
|
56
67
|
Jekyll::Hooks.register :site, :after_init do |site|
|
68
|
+
# load config
|
57
69
|
self.load(site.config)
|
70
|
+
# dispatch site after_init event
|
71
|
+
Manager.dispatch(site, :site, :after_init)
|
58
72
|
end
|
59
73
|
end
|
60
74
|
end
|
@@ -14,6 +14,7 @@ module Jekyll::Spaceship
|
|
14
14
|
container = _register.first
|
15
15
|
events = _register.last.uniq
|
16
16
|
events = events.select do |event|
|
17
|
+
next true if event.match(/^after/)
|
17
18
|
next true if event.match(/^post/)
|
18
19
|
next events.index(event.to_s.gsub(/^pre/, 'post').to_sym).nil?
|
19
20
|
end
|
@@ -59,21 +60,25 @@ module Jekyll::Spaceship
|
|
59
60
|
def self.dispatch(page, container, event)
|
60
61
|
@@_processors.each do |processor|
|
61
62
|
processor.dispatch page, container, event
|
63
|
+
break unless processor.next?
|
62
64
|
end
|
63
65
|
if event.to_s.start_with?('post') and Type.html? output_ext(page)
|
64
66
|
self.dispatch_html_block(page)
|
65
67
|
end
|
66
68
|
@@_processors.each do |processor|
|
67
69
|
processor.on_handled if processor.handled
|
70
|
+
break unless processor.next?
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
71
74
|
def self.ext(page)
|
75
|
+
return unless page.respond_to? :path
|
72
76
|
ext = page.path.match(/\.[^.]+$/)
|
73
77
|
ext.to_s.rstrip
|
74
78
|
end
|
75
79
|
|
76
80
|
def self.output_ext(page)
|
81
|
+
return unless page.respond_to? :url_placeholders
|
77
82
|
page.url_placeholders[:output_ext]
|
78
83
|
end
|
79
84
|
|
@@ -25,7 +25,11 @@ module Jekyll::Spaceship
|
|
25
25
|
attr_accessor :handled
|
26
26
|
|
27
27
|
def name
|
28
|
-
self.class.
|
28
|
+
self.class.class_name
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.class_name
|
32
|
+
self.name.split('::').last
|
29
33
|
end
|
30
34
|
|
31
35
|
def filename
|
@@ -86,6 +90,10 @@ module Jekyll::Spaceship
|
|
86
90
|
def self.config
|
87
91
|
end
|
88
92
|
|
93
|
+
def next?
|
94
|
+
true
|
95
|
+
end
|
96
|
+
|
89
97
|
def process?
|
90
98
|
Type.html?(output_ext) or Type.markdown?(ext)
|
91
99
|
end
|
@@ -190,6 +198,20 @@ module Jekyll::Spaceship
|
|
190
198
|
content
|
191
199
|
end
|
192
200
|
|
201
|
+
def get_exclusion(id)
|
202
|
+
result = nil
|
203
|
+
match_data = id.match /<!JEKYLL@(.+)@(.+)>/
|
204
|
+
unless match_data.nil?
|
205
|
+
id = match_data[2].to_i
|
206
|
+
result = {
|
207
|
+
:id => id,
|
208
|
+
:marker => match_data[0],
|
209
|
+
:content => @exclusion_store[id]
|
210
|
+
}
|
211
|
+
end
|
212
|
+
result
|
213
|
+
end
|
214
|
+
|
193
215
|
def self.escape_html(content)
|
194
216
|
# escape link
|
195
217
|
content.scan(/((https?:)?\/\/\S+\?[a-zA-Z0-9%\-_=\.&;]+)/) do |result|
|
@@ -212,6 +234,7 @@ module Jekyll::Spaceship
|
|
212
234
|
'body' => content_body
|
213
235
|
}
|
214
236
|
rescue StandardError => msg
|
237
|
+
logger = Logger.new(self.class_name)
|
215
238
|
logger.log msg
|
216
239
|
end
|
217
240
|
end
|
@@ -232,5 +255,31 @@ module Jekyll::Spaceship
|
|
232
255
|
"<img class=\"#{css_class}\" src=\"#{body}\">"
|
233
256
|
end
|
234
257
|
end
|
258
|
+
|
259
|
+
def self.handle_bang_link(
|
260
|
+
content,
|
261
|
+
url = '(https?:)?\\/\\/.*',
|
262
|
+
title = '("(.*)".*){0,1}',
|
263
|
+
&block
|
264
|
+
)
|
265
|
+
# pre-handle reference-style links
|
266
|
+
regex = /(\[(.*)\]:\s*(#{url}\s*#{title}))/
|
267
|
+
content.scan regex do |match_data|
|
268
|
+
match = match_data[0]
|
269
|
+
ref_name = match_data[1]
|
270
|
+
ref_value = match_data[2]
|
271
|
+
content = content.gsub(match, '')
|
272
|
+
.gsub(/\!\[(.*)\]\s*\[#{ref_name}\]/,
|
273
|
+
"![\1](#{ref_value})")
|
274
|
+
end
|
275
|
+
|
276
|
+
# handle inline-style links
|
277
|
+
regex = /(\!\[(.*)\]\(.*#{url}\s*#{title}\))/
|
278
|
+
content.scan regex do |match_data|
|
279
|
+
url = match_data[2]
|
280
|
+
title = match_data[6]
|
281
|
+
block.call(url, title)
|
282
|
+
end
|
283
|
+
end
|
235
284
|
end
|
236
285
|
end
|
@@ -11,14 +11,42 @@ module Jekyll::Spaceship
|
|
11
11
|
'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js',
|
12
12
|
],
|
13
13
|
'config' => {
|
14
|
-
'tex' => {
|
14
|
+
'tex' => {
|
15
|
+
'inlineMath' => [['$','$'], ['\\(','\\)']],
|
16
|
+
'displayMath' => [['$$','$$'], ['\\[','\\]']]
|
17
|
+
},
|
15
18
|
'svg': { 'fontCache': 'global' }
|
19
|
+
},
|
20
|
+
'optimize' => {
|
21
|
+
'enabled' => true,
|
22
|
+
'include' => [],
|
23
|
+
'exclude' => []
|
16
24
|
}
|
17
25
|
}
|
18
26
|
end
|
19
27
|
|
20
28
|
def process?
|
21
|
-
return true if Type.html?(output_ext)
|
29
|
+
return true if Type.html?(output_ext) or Type.markdown?(output_ext)
|
30
|
+
end
|
31
|
+
|
32
|
+
def on_handle_markdown(content)
|
33
|
+
# pre-handle mathjax expressions in markdown
|
34
|
+
patterns = get_math_patterns()
|
35
|
+
patterns['include'].each do |pattern|
|
36
|
+
content.scan(pattern) do |result|
|
37
|
+
expr = result[0]
|
38
|
+
is_excluded = false
|
39
|
+
patterns['exclude'].each do |pe|
|
40
|
+
break is_excluded = true if expr.match(/#{pe}/)
|
41
|
+
end
|
42
|
+
next if is_excluded
|
43
|
+
escaped_expr = expr
|
44
|
+
.gsub(/(?<!^)\\(?!\S$)/, '\\\\\\\\')
|
45
|
+
.gsub(/\\ /, '\\\\\\ ')
|
46
|
+
content = content.gsub(expr, escaped_expr)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
content
|
22
50
|
end
|
23
51
|
|
24
52
|
def on_handle_html(content)
|
@@ -45,22 +73,60 @@ module Jekyll::Spaceship
|
|
45
73
|
end
|
46
74
|
|
47
75
|
def has_mathjax_expression?(doc)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
76
|
+
return true unless config['optimize']['enabled'] == true
|
77
|
+
scan_mathjax_expression(doc) do
|
78
|
+
return true
|
79
|
+
end
|
80
|
+
false
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_math_patterns()
|
84
|
+
patterns = []
|
85
|
+
math_patterns = []
|
86
|
+
['tex', 'tex2jax'].each do |t|
|
87
|
+
['inlineMath', 'displayMath'].each do |m|
|
88
|
+
r = config.dig('config', t, m)
|
89
|
+
r&.each do |i|
|
90
|
+
btag = Regexp.escape(i[0])
|
91
|
+
etag = Regexp.escape(i[1])
|
92
|
+
patterns <<= /((?<!\\\\)#{btag}.+?(?<!\\\\)#{etag})/
|
93
|
+
end
|
54
94
|
end
|
55
95
|
end
|
96
|
+
config['optimize']['include'].each do |pattern|
|
97
|
+
patterns <<= /(#{pattern})/
|
98
|
+
end
|
99
|
+
{
|
100
|
+
'include' => patterns,
|
101
|
+
'exclude' => config['optimize']['exclude']
|
102
|
+
}
|
103
|
+
end
|
56
104
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
105
|
+
def scan_mathjax_expression(doc, &block)
|
106
|
+
patterns = get_math_patterns()
|
107
|
+
doc.css('*').each do |node|
|
108
|
+
next if ['code', 'pre', 'figure'].include? node.name
|
109
|
+
next if node.ancestors('code, pre, figure').size > 0
|
110
|
+
next if node.children.size > 1
|
111
|
+
patterns['include'].each do |pattern|
|
112
|
+
# check scripting mathjax expression
|
113
|
+
if node.name == 'script'
|
114
|
+
type = node['type']
|
115
|
+
next unless type
|
116
|
+
next unless type.match(/math\/tex/)
|
117
|
+
end
|
118
|
+
# check normal mathjax expression
|
119
|
+
node.content.scan(pattern) do |result|
|
120
|
+
expr = result[0]
|
121
|
+
is_excluded = false
|
122
|
+
patterns['exclude'].each do |pe|
|
123
|
+
break is_excluded = true if expr.match(/#{pe}/)
|
124
|
+
end
|
125
|
+
next if is_excluded
|
126
|
+
block.call(node, expr)
|
127
|
+
end
|
61
128
|
end
|
62
129
|
end
|
63
|
-
false
|
64
130
|
end
|
65
131
|
end
|
66
132
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-spaceship
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jeffreytse
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -114,7 +114,7 @@ dependencies:
|
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '3.0'
|
117
|
-
description:
|
117
|
+
description:
|
118
118
|
email:
|
119
119
|
- jeffreytse.mail@gmail.com
|
120
120
|
executables: []
|
@@ -155,7 +155,7 @@ homepage: https://github.com/jeffreytse/jekyll-spaceship
|
|
155
155
|
licenses:
|
156
156
|
- MIT
|
157
157
|
metadata: {}
|
158
|
-
post_install_message:
|
158
|
+
post_install_message:
|
159
159
|
rdoc_options: []
|
160
160
|
require_paths:
|
161
161
|
- lib
|
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
version: '0'
|
172
172
|
requirements: []
|
173
173
|
rubygems_version: 3.0.8
|
174
|
-
signing_key:
|
174
|
+
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: A Jekyll plugin to provide powerful supports for table, mathjax, plantuml,
|
177
177
|
mermaid, emoji, video, audio, youtube, vimeo, dailymotion, spotify, soundcloud,
|