jekyll-spaceship 0.4.2 → 0.4.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/.codeclimate.yml +38 -0
- data/lib/jekyll-spaceship/cores/manager.rb +118 -0
- data/lib/jekyll-spaceship/cores/processor.rb +59 -226
- data/lib/jekyll-spaceship/cores/register.rb +0 -4
- data/lib/jekyll-spaceship/cores/type.rb +41 -0
- data/lib/jekyll-spaceship/processors/mathjax-processor.rb +9 -3
- data/lib/jekyll-spaceship/processors/table-processor.rb +49 -52
- data/lib/jekyll-spaceship/version.rb +1 -1
- data/lib/jekyll-spaceship.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b764caa91610338387d31e7e46e9e8a76bad9de85ae35218e5e555080fe84566
|
4
|
+
data.tar.gz: ae0a3cb843e45c686f15e467809bf885692809edf54cca48a4667c6cc2685280
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39c4090c57da17685ae4af607a5267799a71e39df0740c5e9e65ef0de121e28ae4bf735e00a55373f7ce5446424684930ce9864f82578d0eb28ed0e20e68cf80
|
7
|
+
data.tar.gz: ed8ff5bb71e5763a862c6281c0d7572d3e74f082092d165f925b732e720ab02ea26fdb13bc89a9f4333313aa439aad5d0501cab48e8b9c78d862e08d14f13a03
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
version: "2"
|
2
|
+
checks:
|
3
|
+
argument-count:
|
4
|
+
enabled: true
|
5
|
+
config:
|
6
|
+
threshold: 5
|
7
|
+
file-lines:
|
8
|
+
enabled: true
|
9
|
+
config:
|
10
|
+
threshold: 300
|
11
|
+
method-complexity:
|
12
|
+
enabled: true
|
13
|
+
config:
|
14
|
+
threshold: 15
|
15
|
+
method-count:
|
16
|
+
enabled: true
|
17
|
+
config:
|
18
|
+
threshold: 50
|
19
|
+
method-lines:
|
20
|
+
enabled: true
|
21
|
+
config:
|
22
|
+
threshold: 30
|
23
|
+
plugins:
|
24
|
+
fixme:
|
25
|
+
enabled: false
|
26
|
+
|
27
|
+
exclude_patterns:
|
28
|
+
- "*.*"
|
29
|
+
- ".*"
|
30
|
+
|
31
|
+
- Gemfile
|
32
|
+
- LICENSE.txt
|
33
|
+
- Rakefile
|
34
|
+
|
35
|
+
- rake/
|
36
|
+
- script/
|
37
|
+
- spec/
|
38
|
+
- test/
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require __dir__ + '/type'
|
5
|
+
|
6
|
+
module Jekyll::Spaceship
|
7
|
+
class Manager
|
8
|
+
@@_hooks = {}
|
9
|
+
@@_processers = []
|
10
|
+
|
11
|
+
def self.add(processor)
|
12
|
+
# register for listening event
|
13
|
+
processor.registers.each do |_register|
|
14
|
+
container = _register.first
|
15
|
+
events = _register.last.uniq
|
16
|
+
events = events.select do |event|
|
17
|
+
next true if event.match(/^post/)
|
18
|
+
next !events.any?(event.to_s.gsub(/^pre/, 'post').to_sym)
|
19
|
+
end
|
20
|
+
events.each do |event|
|
21
|
+
self.hook container, event
|
22
|
+
end
|
23
|
+
end
|
24
|
+
@@_processers.push(processor)
|
25
|
+
@@_processers = @@_processers.sort { |a, b| b.priority <=> a.priority }
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.hook(container, event, &block)
|
29
|
+
return if not is_hooked? container, event
|
30
|
+
|
31
|
+
handler = ->(page) {
|
32
|
+
self.dispatch page, container, event
|
33
|
+
block.call if block
|
34
|
+
}
|
35
|
+
|
36
|
+
if event.to_s.start_with?('after')
|
37
|
+
Jekyll::Hooks.register container, event do |page|
|
38
|
+
handler.call page
|
39
|
+
end
|
40
|
+
elsif event.to_s.start_with?('post')
|
41
|
+
Jekyll::Hooks.register container, event do |page|
|
42
|
+
handler.call page
|
43
|
+
end
|
44
|
+
# auto add pre-event
|
45
|
+
self.hook container, event.to_s.sub('post', 'pre').to_sym
|
46
|
+
elsif event.to_s.start_with?('pre')
|
47
|
+
Jekyll::Hooks.register container, event do |page|
|
48
|
+
handler.call page
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.is_hooked?(container, event)
|
54
|
+
hook_name = "#{container}_#{event}".to_sym
|
55
|
+
return false if @@_hooks.has_key? hook_name
|
56
|
+
@@_hooks[hook_name] = true
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.dispatch(page, container, event)
|
60
|
+
@@_processers.each do |processor|
|
61
|
+
processor.dispatch page, container, event
|
62
|
+
end
|
63
|
+
if event.to_s.start_with?('post') and Type.html? output_ext(page)
|
64
|
+
self.dispatch_html_block(page)
|
65
|
+
end
|
66
|
+
@@_processers.each do |processor|
|
67
|
+
processor.on_handled if processor.handled
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.ext(page)
|
72
|
+
page.data['ext']
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.output_ext(page)
|
76
|
+
page.url_placeholders[:output_ext]
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.converter(page, name)
|
80
|
+
page.site.converters.each do |converter|
|
81
|
+
class_name = converter.class.to_s.downcase
|
82
|
+
return converter if class_name.end_with?(name.downcase)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.dispatch_html_block(page)
|
87
|
+
doc = Nokogiri::HTML(page.output)
|
88
|
+
doc.css('script').each do |node|
|
89
|
+
type = Type.html_block_type node['type']
|
90
|
+
content = node.content
|
91
|
+
next if type.nil?
|
92
|
+
|
93
|
+
# dispatch to on_handle_html_block
|
94
|
+
@@_processers.each do |processor|
|
95
|
+
next unless processor.process?
|
96
|
+
content = processor.on_handle_html_block content, type
|
97
|
+
# dispatch to type handlers
|
98
|
+
method = "on_handle_#{type}"
|
99
|
+
next unless processor.respond_to? method
|
100
|
+
content = processor.pre_exclude content
|
101
|
+
content = processor.send method, content
|
102
|
+
content = processor.after_exclude content
|
103
|
+
end
|
104
|
+
|
105
|
+
cvter = self.converter page, type
|
106
|
+
content = cvter.convert content unless cvter.nil?
|
107
|
+
|
108
|
+
# dispatch to on_handle_html
|
109
|
+
@@_processers.each do |processor|
|
110
|
+
next unless processor.process?
|
111
|
+
content = processor.on_handle_html content
|
112
|
+
end
|
113
|
+
node.replace Nokogiri::HTML.fragment content
|
114
|
+
end
|
115
|
+
page.output = doc.to_html
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -1,56 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'nokogiri'
|
4
|
-
|
5
3
|
module Jekyll::Spaceship
|
6
4
|
class Processor
|
7
|
-
@@_hooks = {}
|
8
|
-
@@_registers = []
|
9
|
-
@@_processers = []
|
10
|
-
@@_exclusions = []
|
11
|
-
@@_priority = nil
|
12
|
-
|
13
|
-
attr_accessor :priority
|
14
|
-
attr_accessor :page
|
15
|
-
attr_accessor :handled
|
16
|
-
|
17
5
|
DEFAULT_PRIORITY = 20
|
18
6
|
|
19
7
|
PRIORITY_MAP = {
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
8
|
+
:lowest => 0,
|
9
|
+
:low => 10,
|
10
|
+
:normal => 20,
|
11
|
+
:high => 30,
|
12
|
+
:highest => 40,
|
23
13
|
}.freeze
|
24
14
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
.htm
|
29
|
-
).freeze
|
30
|
-
|
31
|
-
CSS_EXTENSIONS = %w(
|
32
|
-
.css
|
33
|
-
.scss
|
34
|
-
).freeze
|
15
|
+
@@_registers = []
|
16
|
+
@@_exclusions = []
|
17
|
+
@@_priority = nil
|
35
18
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
19
|
+
attr_reader :page
|
20
|
+
attr_reader :priority
|
21
|
+
attr_reader :registers
|
22
|
+
attr_reader :exclusions
|
23
|
+
attr_accessor :handled
|
40
24
|
|
41
25
|
def initialize()
|
42
26
|
self.initialize_priority
|
43
27
|
self.initialize_register
|
44
28
|
self.initialize_exclusions
|
29
|
+
Manager.add self
|
45
30
|
end
|
46
31
|
|
47
32
|
def initialize_priority
|
48
|
-
@@_priority = DEFAULT_PRIORITY if @@_priority.nil?
|
49
33
|
@priority = @@_priority
|
34
|
+
unless @priority.nil? or @priority.is_a? Numeric
|
35
|
+
@priority = PRIORITY_MAP[@priority.to_sym]
|
36
|
+
end
|
37
|
+
@priority = DEFAULT_PRIORITY if @priority.nil?
|
50
38
|
@@_priority = nil
|
51
|
-
|
52
|
-
@@_processers.push(self)
|
53
|
-
@@_processers = @@_processers.sort { |a, b| b.priority <=> a.priority }
|
54
39
|
end
|
55
40
|
|
56
41
|
def initialize_register
|
@@ -58,18 +43,7 @@ module Jekyll::Spaceship
|
|
58
43
|
self.class.register :pages, :pre_render, :post_render
|
59
44
|
self.class.register :posts, :pre_render, :post_render
|
60
45
|
end
|
61
|
-
|
62
|
-
@@_registers.each do |_register|
|
63
|
-
container = _register.first
|
64
|
-
events = _register.last.uniq
|
65
|
-
events = events.select do |event|
|
66
|
-
next true if event.match(/^post/)
|
67
|
-
next !events.any?(event.to_s.gsub(/^pre/, 'post').to_sym)
|
68
|
-
end
|
69
|
-
events.each do |event|
|
70
|
-
self.class.hook container, event
|
71
|
-
end
|
72
|
-
end
|
46
|
+
@registers = Array.new @@_registers
|
73
47
|
@@_registers.clear
|
74
48
|
end
|
75
49
|
|
@@ -77,165 +51,85 @@ module Jekyll::Spaceship
|
|
77
51
|
if @@_exclusions.size.zero?
|
78
52
|
self.class.exclude :code, :block_quotes
|
79
53
|
end
|
80
|
-
@
|
54
|
+
@exclusions = @@_exclusions.uniq
|
81
55
|
@@_exclusions.clear
|
82
56
|
end
|
83
57
|
|
84
58
|
def self.priority(value)
|
85
|
-
|
86
|
-
if PRIORITY_MAP.has_key? value
|
87
|
-
@@_priority = PRIORITY_MAP[value]
|
88
|
-
elsif value.nil?
|
89
|
-
@@_priority = DEFAULT_PRIORITY
|
90
|
-
else
|
91
|
-
@@_priority = value
|
92
|
-
end
|
59
|
+
@@_priority = value.to_sym
|
93
60
|
end
|
94
61
|
|
95
62
|
def self.register(container, *events)
|
96
63
|
@@_registers << [container, events]
|
97
64
|
end
|
98
65
|
|
99
|
-
def self.
|
100
|
-
|
101
|
-
return false if @@_hooks.has_key? hook_name
|
102
|
-
@@_hooks[hook_name] = true
|
66
|
+
def self.exclude(*types)
|
67
|
+
@@_exclusions = types
|
103
68
|
end
|
104
69
|
|
105
|
-
def
|
106
|
-
|
70
|
+
def process?
|
71
|
+
Type.html?(output_ext) or Type.markdown?(ext)
|
72
|
+
end
|
107
73
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
processor.page = instance
|
112
|
-
processor.handled = false
|
113
|
-
next if not processor.process?
|
114
|
-
processor.dispatch container, event
|
115
|
-
end
|
116
|
-
if event.to_s.start_with?('post') and self.html? output_ext(instance)
|
117
|
-
self.handle_html_block(instance)
|
118
|
-
end
|
119
|
-
@@_processers.each do |processor|
|
120
|
-
processor.page = instance
|
121
|
-
if processor.handled
|
122
|
-
processor.on_handled
|
123
|
-
end
|
124
|
-
end
|
125
|
-
block.call if block
|
126
|
-
}
|
74
|
+
def ext
|
75
|
+
Manager.ext @page
|
76
|
+
end
|
127
77
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
end
|
132
|
-
elsif event.to_s.start_with?('post')
|
133
|
-
Jekyll::Hooks.register container, event do |instance|
|
134
|
-
dispatch.call instance
|
135
|
-
end
|
78
|
+
def output_ext
|
79
|
+
Manager.output_ext @page
|
80
|
+
end
|
136
81
|
|
137
|
-
|
138
|
-
|
139
|
-
elsif event.to_s.start_with?('pre')
|
140
|
-
Jekyll::Hooks.register container, event do |instance|
|
141
|
-
dispatch.call instance
|
142
|
-
end
|
143
|
-
end
|
82
|
+
def converter(name)
|
83
|
+
Manager.converter @page, name
|
144
84
|
end
|
145
85
|
|
146
|
-
def dispatch(container, event)
|
86
|
+
def dispatch(page, container, event)
|
87
|
+
@page = page
|
88
|
+
@handled = false
|
89
|
+
return unless self.process?
|
147
90
|
method = "on_#{container}_#{event}"
|
148
91
|
self.send method, @page if self.respond_to? method
|
149
|
-
|
92
|
+
method = ''
|
150
93
|
if event.to_s.start_with?('pre')
|
151
|
-
if markdown? ext
|
94
|
+
if Type.markdown? ext
|
152
95
|
method = 'on_handle_markdown'
|
153
|
-
else
|
154
|
-
method = ''
|
155
96
|
end
|
156
|
-
|
157
97
|
if self.respond_to? method
|
158
98
|
@page.content = self.pre_exclude @page.content
|
159
99
|
@page.content = self.send method, @page.content
|
160
100
|
@page.content = self.after_exclude @page.content
|
161
101
|
end
|
162
102
|
else
|
163
|
-
if html? output_ext
|
103
|
+
if Type.html? output_ext
|
164
104
|
method = 'on_handle_html'
|
165
105
|
elsif css? output_ext
|
166
106
|
method = 'on_handle_css'
|
167
|
-
else
|
168
|
-
method = ''
|
169
107
|
end
|
170
|
-
|
171
108
|
if self.respond_to? method
|
172
109
|
@page.output = self.send method, @page.output
|
173
110
|
end
|
174
111
|
end
|
175
112
|
end
|
176
113
|
|
177
|
-
def
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
def html?(_ext)
|
182
|
-
self.class.html? _ext
|
183
|
-
end
|
184
|
-
|
185
|
-
def css?(_ext)
|
186
|
-
self.class.css? _ext
|
187
|
-
end
|
188
|
-
|
189
|
-
def markdown?(_ext)
|
190
|
-
self.class.markdown? _ext
|
191
|
-
end
|
192
|
-
|
193
|
-
def self.html?(_ext)
|
194
|
-
HTML_EXTENSIONS.include?(_ext)
|
195
|
-
end
|
196
|
-
|
197
|
-
def self.css?(_ext)
|
198
|
-
CSS_EXTENSIONS.include?(_ext)
|
199
|
-
end
|
200
|
-
|
201
|
-
def self.markdown?(_ext)
|
202
|
-
MD_EXTENSIONS.include?(_ext)
|
203
|
-
end
|
204
|
-
|
205
|
-
def converter(name)
|
206
|
-
self.class.converter(@page, name)
|
207
|
-
end
|
208
|
-
|
209
|
-
def self.converter(instance, name)
|
210
|
-
instance.site.converters.each do |converter|
|
211
|
-
class_name = converter.class.to_s.downcase
|
212
|
-
return converter if class_name.end_with?(name.downcase)
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
def ext
|
217
|
-
self.class.ext @page
|
218
|
-
end
|
219
|
-
|
220
|
-
def output_ext
|
221
|
-
self.class.output_ext @page
|
222
|
-
end
|
223
|
-
|
224
|
-
def self.ext(instance)
|
225
|
-
instance.data['ext']
|
114
|
+
def on_handle_html_block(content, type)
|
115
|
+
# default handle method
|
116
|
+
content
|
226
117
|
end
|
227
118
|
|
228
|
-
def
|
229
|
-
|
119
|
+
def on_handle_html(content)
|
120
|
+
# default handle method
|
121
|
+
content
|
230
122
|
end
|
231
123
|
|
232
|
-
def
|
233
|
-
|
124
|
+
def on_handled
|
125
|
+
processor = self.class.name.split('::').last
|
126
|
+
file = page.path.gsub(/.*_posts\//, '')
|
127
|
+
Logger.log "[#{processor}] #{file}"
|
234
128
|
end
|
235
129
|
|
236
130
|
def pre_exclude(content)
|
237
|
-
@
|
238
|
-
@
|
131
|
+
@exclusion_store = []
|
132
|
+
@exclusions.each do |type|
|
239
133
|
regex = nil
|
240
134
|
if type == :code
|
241
135
|
regex = /(`{3}\s*(\w*)((?:.|\n)*?)`{3})/
|
@@ -243,83 +137,22 @@ module Jekyll::Spaceship
|
|
243
137
|
next if regex.nil?
|
244
138
|
content.scan(regex) do |match_data|
|
245
139
|
match = match_data[0]
|
246
|
-
id = @
|
140
|
+
id = @exclusion_store.size
|
247
141
|
content = content.gsub(match, "[//]: JEKYLL_EXCLUDE_##{id}")
|
248
|
-
@
|
142
|
+
@exclusion_store.push match
|
249
143
|
end
|
250
144
|
end
|
251
145
|
content
|
252
146
|
end
|
253
147
|
|
254
148
|
def after_exclude(content)
|
255
|
-
while @
|
256
|
-
match = @
|
257
|
-
id = @
|
149
|
+
while @exclusion_store.size > 0
|
150
|
+
match = @exclusion_store.pop
|
151
|
+
id = @exclusion_store.size
|
258
152
|
content = content.gsub("[//]: JEKYLL_EXCLUDE_##{id}", match)
|
259
153
|
end
|
260
|
-
@
|
154
|
+
@exclusion_store = []
|
261
155
|
content
|
262
156
|
end
|
263
|
-
|
264
|
-
def on_handled
|
265
|
-
processor = self.class.name.split('::').last
|
266
|
-
file = page.path.gsub(/.*_posts\//, '')
|
267
|
-
Logger.log "[#{processor}] #{file}"
|
268
|
-
end
|
269
|
-
|
270
|
-
def self.handle_html_block(instance)
|
271
|
-
doc = Nokogiri::HTML(instance.output)
|
272
|
-
|
273
|
-
doc.css('script').each do |node|
|
274
|
-
blk_type = node['type']
|
275
|
-
blk_content = node.content
|
276
|
-
|
277
|
-
cvter = nil
|
278
|
-
method = ''
|
279
|
-
block_method = 'on_handle_html_block'
|
280
|
-
|
281
|
-
case blk_type
|
282
|
-
when 'text/markdown'
|
283
|
-
method = 'on_handle_markdown'
|
284
|
-
cvter = self.converter(instance, 'markdown')
|
285
|
-
end
|
286
|
-
|
287
|
-
@@_processers.each do |processor|
|
288
|
-
processor.page = instance
|
289
|
-
next if not processor.process?
|
290
|
-
|
291
|
-
# dispatch to on_handle_html_block
|
292
|
-
if processor.respond_to? block_method
|
293
|
-
blk_content = processor.send block_method blk_content, blk_type
|
294
|
-
end
|
295
|
-
|
296
|
-
# dispatch to other handlers
|
297
|
-
if processor.respond_to? method
|
298
|
-
blk_content = processor.pre_exclude blk_content
|
299
|
-
blk_content = processor.send method, blk_content
|
300
|
-
blk_content = processor.after_exclude blk_content
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
if not cvter.nil?
|
305
|
-
blk_content = cvter.convert blk_content
|
306
|
-
end
|
307
|
-
|
308
|
-
next if method == ''
|
309
|
-
|
310
|
-
method = 'on_handle_html'
|
311
|
-
@@_processers.each do |processor|
|
312
|
-
processor.page = instance
|
313
|
-
next if not processor.process?
|
314
|
-
if processor.respond_to? method
|
315
|
-
blk_content = processor.send method, blk_content
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
node.replace Nokogiri::HTML.fragment(blk_content)
|
320
|
-
end
|
321
|
-
|
322
|
-
instance.output = doc.to_html
|
323
|
-
end
|
324
157
|
end
|
325
158
|
end
|
@@ -25,17 +25,13 @@ module Jekyll::Spaceship
|
|
25
25
|
next if filename.gsub(/-/, '').downcase != name
|
26
26
|
|
27
27
|
Logger.log "use #{filename}"
|
28
|
-
|
29
28
|
require path
|
30
|
-
|
31
29
|
constants = Jekyll::Spaceship.constants.select do |c|
|
32
30
|
c.downcase.to_s == name
|
33
31
|
end
|
34
32
|
|
35
33
|
next if constants.first.nil?
|
36
|
-
|
37
34
|
_class = Jekyll::Spaceship.const_get(constants.first)
|
38
|
-
|
39
35
|
next unless _class.is_a? Class
|
40
36
|
|
41
37
|
_class.new
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll::Spaceship
|
4
|
+
class Type
|
5
|
+
HTML_EXTENSIONS = %w(
|
6
|
+
.html
|
7
|
+
.xhtml
|
8
|
+
.htm
|
9
|
+
).freeze
|
10
|
+
|
11
|
+
CSS_EXTENSIONS = %w(
|
12
|
+
.css
|
13
|
+
.scss
|
14
|
+
).freeze
|
15
|
+
|
16
|
+
MD_EXTENSIONS = %w(
|
17
|
+
.md
|
18
|
+
.markdown
|
19
|
+
).freeze
|
20
|
+
|
21
|
+
HTML_BLOCK_TYPE_MAP = {
|
22
|
+
'text/markdown' => 'markdown',
|
23
|
+
}.freeze
|
24
|
+
|
25
|
+
def self.html?(_ext)
|
26
|
+
HTML_EXTENSIONS.include?(_ext)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.css?(_ext)
|
30
|
+
CSS_EXTENSIONS.include?(_ext)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.markdown?(_ext)
|
34
|
+
MD_EXTENSIONS.include?(_ext)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.html_block_type(type)
|
38
|
+
HTML_BLOCK_TYPE_MAP[type]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -5,7 +5,7 @@ require "nokogiri"
|
|
5
5
|
module Jekyll::Spaceship
|
6
6
|
class MathjaxProcessor < Processor
|
7
7
|
def process?
|
8
|
-
return true if html?(output_ext)
|
8
|
+
return true if Type.html?(output_ext)
|
9
9
|
end
|
10
10
|
|
11
11
|
def on_handle_html(content)
|
@@ -20,7 +20,10 @@ module Jekyll::Spaceship
|
|
20
20
|
|
21
21
|
params = "config=TeX-AMS-MML_HTMLorMML"
|
22
22
|
src = "//cdn.mathjax.org/mathjax/latest/MathJax.js?#{params}"
|
23
|
-
config = "MathJax.Hub.Config({
|
23
|
+
config = "MathJax.Hub.Config({ \
|
24
|
+
tex2jax: { inlineMath: [['$','$'], ['\\\\(','\\\\)']] } \
|
25
|
+
});"
|
26
|
+
|
24
27
|
head.add_child("<script src=\"#{src}\">#{config}</script>")
|
25
28
|
|
26
29
|
doc.to_html
|
@@ -28,7 +31,10 @@ module Jekyll::Spaceship
|
|
28
31
|
|
29
32
|
def has_mathjax_expression?(doc)
|
30
33
|
doc.css('*').each do |node|
|
31
|
-
if node.content.match(
|
34
|
+
if node.content.match(/(?<!\\)\$.+(?<!\\)\$/)
|
35
|
+
return true
|
36
|
+
end
|
37
|
+
if node.content.match(/(?<!\\)\\\(.+(?<!\\)\\\)/)
|
32
38
|
return true
|
33
39
|
end
|
34
40
|
end
|
@@ -46,23 +46,7 @@ module Jekyll::Spaceship
|
|
46
46
|
# use nokogiri to parse html content
|
47
47
|
doc = Nokogiri::HTML(content)
|
48
48
|
|
49
|
-
data =
|
50
|
-
data.reset = ->(scope, namespace = nil) {
|
51
|
-
data._.marshal_dump.each do |key, val|
|
52
|
-
if namespace == key or namespace.nil?
|
53
|
-
data._[key][scope] = OpenStruct.new
|
54
|
-
end
|
55
|
-
end
|
56
|
-
}
|
57
|
-
data.scope = ->(namespace) {
|
58
|
-
if not data._[namespace]
|
59
|
-
data._[namespace] = OpenStruct.new(
|
60
|
-
table: OpenStruct.new,
|
61
|
-
row: OpenStruct.new
|
62
|
-
)
|
63
|
-
end
|
64
|
-
data._[namespace]
|
65
|
-
}
|
49
|
+
data = self.table_scope_data
|
66
50
|
|
67
51
|
# handle each table
|
68
52
|
doc.css('table').each do |table|
|
@@ -96,45 +80,63 @@ module Jekyll::Spaceship
|
|
96
80
|
doc.to_html
|
97
81
|
end
|
98
82
|
|
83
|
+
def table_scope_data
|
84
|
+
data = OpenStruct.new(_: OpenStruct.new)
|
85
|
+
data.reset = ->(scope, namespace = nil) {
|
86
|
+
data._.marshal_dump.each do |key, val|
|
87
|
+
if namespace == key or namespace.nil?
|
88
|
+
data._[key][scope] = OpenStruct.new
|
89
|
+
end
|
90
|
+
end
|
91
|
+
}
|
92
|
+
data.scope = ->(namespace) {
|
93
|
+
if not data._[namespace]
|
94
|
+
data._[namespace] = OpenStruct.new(
|
95
|
+
table: OpenStruct.new,
|
96
|
+
row: OpenStruct.new
|
97
|
+
)
|
98
|
+
end
|
99
|
+
data._[namespace]
|
100
|
+
}
|
101
|
+
data
|
102
|
+
end
|
103
|
+
|
99
104
|
def handle_colspan(data)
|
100
105
|
scope = data.scope.call __method__
|
101
|
-
scope_table = scope.table
|
102
|
-
scope_row = scope.row
|
103
106
|
cells = data.cells
|
104
107
|
cell = data.cell
|
105
108
|
|
106
|
-
if
|
107
|
-
|
108
|
-
|
109
|
+
if scope.table.row != data.row
|
110
|
+
scope.table.row = data.row
|
111
|
+
scope.row.colspan = 0
|
109
112
|
end
|
110
113
|
|
111
114
|
# handle colspan
|
112
115
|
result = cell.content.match(/(\s*\|)+$/)
|
113
|
-
if cell == cells.last and
|
114
|
-
range = (cells.count -
|
116
|
+
if cell == cells.last and scope.row.colspan > 0
|
117
|
+
range = (cells.count - scope.row.colspan)...cells.count
|
115
118
|
for i in range do
|
116
119
|
cells[i].remove
|
117
120
|
end
|
118
121
|
end
|
119
122
|
if result
|
120
123
|
result = result[0]
|
121
|
-
|
124
|
+
scope.row.colspan += result.scan(/\|/).count
|
122
125
|
cell.content = cell.content.gsub(/(\s*\|)+$/, '')
|
123
|
-
cell.set_attribute('colspan',
|
126
|
+
cell.set_attribute('colspan', scope.row.colspan + 1)
|
124
127
|
end
|
125
128
|
end
|
126
129
|
|
127
130
|
def handle_multi_rows(data)
|
128
131
|
scope = data.scope.call __method__
|
129
|
-
scope_table = scope.table
|
130
132
|
cells = data.cells
|
131
133
|
row = data.row
|
132
134
|
cell = data.cell
|
133
135
|
|
134
|
-
if
|
135
|
-
|
136
|
-
|
137
|
-
|
136
|
+
if scope.table.table != data.table
|
137
|
+
scope.table.table = data.table
|
138
|
+
scope.table.multi_row_cells = nil
|
139
|
+
scope.table.multi_row_start = false
|
138
140
|
end
|
139
141
|
|
140
142
|
# handle multi-rows
|
@@ -143,41 +145,38 @@ module Jekyll::Spaceship
|
|
143
145
|
match = cell.content.match(/(?<!\\)\\\s*$/)
|
144
146
|
if match
|
145
147
|
cell.content = cell.content.gsub(/(?<!\\)\\\s*$/, '')
|
146
|
-
if not
|
147
|
-
|
148
|
-
|
148
|
+
if not scope.table.multi_row_start
|
149
|
+
scope.table.multi_row_cells = cells
|
150
|
+
scope.table.multi_row_start = true
|
149
151
|
end
|
150
152
|
end
|
151
153
|
|
152
|
-
if
|
153
|
-
for i in 0...
|
154
|
-
multi_row_cell =
|
154
|
+
if scope.table.multi_row_cells != cells and scope.table.multi_row_start
|
155
|
+
for i in 0...scope.table.multi_row_cells.count do
|
156
|
+
multi_row_cell = scope.table.multi_row_cells[i]
|
155
157
|
multi_row_cell.content += " \n#{cells[i].content}"
|
156
158
|
end
|
157
159
|
row.remove
|
158
160
|
end
|
159
|
-
|
161
|
+
scope.table.multi_row_start = false if not match
|
160
162
|
end
|
161
163
|
|
162
164
|
def handle_rowspan(data)
|
163
165
|
scope = data.scope.call __method__
|
164
|
-
scope_table = scope.table
|
165
|
-
scope_row = scope.row
|
166
166
|
cell = data.cell
|
167
167
|
cells = data.cells
|
168
168
|
|
169
|
-
if
|
170
|
-
|
171
|
-
|
169
|
+
if scope.table.table != data.table
|
170
|
+
scope.table.table = data.table
|
171
|
+
scope.table.span_row_cells = []
|
172
172
|
end
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
scope_row.col_index = 0
|
173
|
+
if scope.row.row != data.row
|
174
|
+
scope.row.row = data.row
|
175
|
+
scope.row.col_index = 0
|
177
176
|
end
|
178
177
|
|
179
178
|
# handle rowspan
|
180
|
-
span_cell =
|
179
|
+
span_cell = scope.table.span_row_cells[scope.row.col_index]
|
181
180
|
if span_cell and cell.content.match(/^\s*\^{2}/)
|
182
181
|
cell.content = cell.content.gsub(/^\s*\^{2}/, '')
|
183
182
|
span_cell.content += " \n#{cell.content}"
|
@@ -186,10 +185,9 @@ module Jekyll::Spaceship
|
|
186
185
|
span_cell.set_attribute('rowspan', "#{rowspan}")
|
187
186
|
cell.remove
|
188
187
|
else
|
189
|
-
|
188
|
+
scope.table.span_row_cells[scope.row.col_index] = cell
|
190
189
|
end
|
191
|
-
|
192
|
-
scope_row.col_index += 1
|
190
|
+
scope.row.col_index += 1
|
193
191
|
end
|
194
192
|
|
195
193
|
def handle_text_align(data)
|
@@ -211,7 +209,6 @@ module Jekyll::Spaceship
|
|
211
209
|
|
212
210
|
# handle text align
|
213
211
|
return if align == 0
|
214
|
-
|
215
212
|
style = cell.get_attribute('style')
|
216
213
|
if align == 1
|
217
214
|
align = 'text-align: left'
|
data/lib/jekyll-spaceship.rb
CHANGED
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.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jeffreytse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -93,6 +93,7 @@ executables: []
|
|
93
93
|
extensions: []
|
94
94
|
extra_rdoc_files: []
|
95
95
|
files:
|
96
|
+
- ".codeclimate.yml"
|
96
97
|
- ".gitignore"
|
97
98
|
- ".travis.yml"
|
98
99
|
- Gemfile
|
@@ -102,8 +103,10 @@ files:
|
|
102
103
|
- jekyll-spaceship.gemspec
|
103
104
|
- lib/jekyll-spaceship.rb
|
104
105
|
- lib/jekyll-spaceship/cores/logger.rb
|
106
|
+
- lib/jekyll-spaceship/cores/manager.rb
|
105
107
|
- lib/jekyll-spaceship/cores/processor.rb
|
106
108
|
- lib/jekyll-spaceship/cores/register.rb
|
109
|
+
- lib/jekyll-spaceship/cores/type.rb
|
107
110
|
- lib/jekyll-spaceship/processors/mathjax-processor.rb
|
108
111
|
- lib/jekyll-spaceship/processors/plantuml-processor.rb
|
109
112
|
- lib/jekyll-spaceship/processors/polyfill-processor.rb
|