jekyll-spaceship 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: feae82926b331a1fc32b0ed226447d3d58b6721c7187035ae3d82f297970e979
4
- data.tar.gz: c34eef77784ba8087689780e75548318a91e188073995bbe0922d27abee1d0bc
3
+ metadata.gz: 51f0576137305906368ec086aba6c9c11d45799d10dc8a22abd5598a4026251a
4
+ data.tar.gz: 1a52f85350f6d2b3e128b637ec040108d993534ec554296cdd2b998e26551aec
5
5
  SHA512:
6
- metadata.gz: b5e6ed122db069ffdc833eec1a360ee90257b356632ba4732a0b47a49a2ef9a41934d7e7de7eb23a03f61cf49d9347183d9d3cad88f1d9b6b79735cf100651a2
7
- data.tar.gz: 8fca41fbf22600014b6c5b87f31b31b744447854effdf0099d446293e78d032bbdcc102a222c58a9fd05c7dd7f6088cea28575181e2e337488bd993c23504f93
6
+ metadata.gz: 1445456d3974c347367ae35c8b8b2ceec320f523931620d3ad4f19f3982ddefff2f9426f9f47318b6e548da9c0b25b0b370733a472250065579c27296785ce49
7
+ data.tar.gz: f78d6fd69910ea7350b77a6d0c8702214d097e8813032fb4254fa53f4521805c5f2b74c3f1ea8c763cb305b145929d6e12810653952ef57c4c32765048ccaffe
data/README.md CHANGED
@@ -441,7 +441,7 @@ Code above would be parsed as:
441
441
  #### Cell Alignment
442
442
 
443
443
  Markdown table syntax use colons ":" for forcing column alignment.
444
- Therefore, here we also use it for foring cell alignment.
444
+ Therefore, here we also use it for forcing cell alignment.
445
445
 
446
446
  Table cell can be set alignment separately.
447
447
 
@@ -37,8 +37,13 @@ module Jekyll::Spaceship
37
37
  def emoji_filter(content, selector)
38
38
  # use nokogiri to parse html
39
39
  doc = Nokogiri::HTML(content)
40
+
40
41
  body = doc.at('body')
41
42
 
43
+ # in case of a page has no the body node, especially when your
44
+ # page's layout field of front matter is nil or unavailable
45
+ return content if body.nil?
46
+
42
47
  # filter nodes (pre, code)
43
48
  nodes = body.css(selector)
44
49
  nodes.each do |node|
@@ -107,17 +107,22 @@ module Jekyll::Spaceship
107
107
 
108
108
  def scan_mathjax_expression(doc, &block)
109
109
  patterns = get_math_patterns()
110
- doc.css('*').each do |node|
111
- next if ['code', 'pre', 'figure'].include? node.name
112
- next if node.ancestors('code, pre, figure').size > 0
113
- next if node.children.size > 1
110
+ doc = doc.clone
111
+
112
+ # remove code, pre, figure nodes
113
+ doc.css('body code, body pre, body figure').each do |node|
114
+ node.remove
115
+ end
116
+
117
+ # remove scripting mathjax expression
118
+ doc.css('body script').each do |node|
119
+ next if node['type']&.match(/math\/tex/)
120
+ node.remove
121
+ end
122
+
123
+ # scan mathjax expressions
124
+ doc.css('body *').each do |node|
114
125
  patterns['include'].each do |pattern|
115
- # check scripting mathjax expression
116
- if node.name == 'script'
117
- type = node['type']
118
- next unless type
119
- next unless type.match(/math\/tex/)
120
- end
121
126
  # check normal mathjax expression
122
127
  node.content.scan(pattern) do |result|
123
128
  expr = result[0]
@@ -42,7 +42,7 @@ module Jekyll::Spaceship
42
42
  handle_media(element, {
43
43
  media_type: 'audio',
44
44
  host: '(https?:\\/\\/)?.*\\/',
45
- id: '(.+?\\.(mp3|wav|ogg|mid|midi|aac|wma))',
45
+ id: '(.+?\\.(mp3|wav|ogg|mid|midi|aac|wma))'
46
46
  })
47
47
  end
48
48
 
@@ -53,7 +53,7 @@ module Jekyll::Spaceship
53
53
  # ![video](//techslides.com/demos/sample-videos/small.mp4?width=400)
54
54
  def handle_normal_video(element)
55
55
  handle_media(element, {
56
- media_type: 'iframe',
56
+ media_type: 'video',
57
57
  host: '(https?:\\/\\/)?.*\\/',
58
58
  id: '(.+?\\.(avi|mp4|webm|ogg|ogv|flv|mkv|mov|wmv|3gp|rmvb|asf))'
59
59
  })
@@ -90,8 +90,8 @@ module Jekyll::Spaceship
90
90
  def handle_dailymotion(element)
91
91
  handle_media(element, {
92
92
  media_type: 'iframe',
93
- host: '(https?:)?\\/\\/.*dai.?ly.*',
94
- id: '(?<=video\\/|\\/)([a-zA-Z0-9\\_\\-]+)',
93
+ host: '(https?:)?\\/\\/(?>www\\.)?dai\\.?ly(?>motion\\.com\\/video)?\\/',
94
+ id: '([a-zA-Z0-9\\_\\-]+)',
95
95
  base_url: "https://www.dailymotion.com/embed/video/"
96
96
  })
97
97
  end
@@ -128,7 +128,7 @@ module Jekyll::Spaceship
128
128
  src = element.get_attribute('src')
129
129
  title = element.get_attribute('title')
130
130
  id = data[:id_from] === 'html' ? '()' : data[:id]
131
- match_data = src.match(/#{host}#{id}\S*/)
131
+ match_data = src&.match(/#{host}#{id}\S*/)
132
132
  return if match_data.nil?
133
133
 
134
134
  media_type = data[:media_type]
@@ -158,6 +158,10 @@ module Jekyll::Spaceship
158
158
  cfg['loop'] = qs['loop'] || data[:loop] || cfg['loop']
159
159
  cfg['style'] += ';display: none;' if qs['hidden']
160
160
  handle_audio(element, { cfg: cfg })
161
+ when 'video'
162
+ cfg['autoplay'] = qs['autoplay'] || data[:autoplay] || cfg['autoplay']
163
+ cfg['loop'] = qs['loop'] || data[:loop] || cfg['loop']
164
+ handle_video(element, { cfg: cfg })
161
165
  when 'iframe'
162
166
  cfg['title'] = title
163
167
  cfg['width'] = qs['width'] || data[:width] || cfg['width']
@@ -179,12 +183,32 @@ module Jekyll::Spaceship
179
183
  " src=\"#{cfg['src']}\""\
180
184
  " style=\"#{cfg['style']}\""\
181
185
  " controls>" \
182
- "<p> Your browser doesn't support HTML5 audio."\
186
+ " Your browser doesn't support HTML5 audio."\
183
187
  " Here is a <a href=\"#{cfg['src']}\">link to download the audio</a>"\
184
- "instead. </p>"\
188
+ " instead."\
185
189
  "</audio>"
186
- doc = Nokogiri::XML(html)
187
- element.replace(doc.children.first)
190
+ doc = Nokogiri::HTML(html)
191
+ return if element.parent.nil?
192
+ element.replace(doc.at('body').children.first)
193
+ end
194
+
195
+ def handle_video(element, data)
196
+ cfg = data[:cfg]
197
+ html = "<video"\
198
+ " id=\"#{cfg['id']}\""\
199
+ " class=\"#{cfg['class']}\""\
200
+ " style=\"#{cfg['style']}\""\
201
+ " #{cfg['autoplay'] ? 'autoplay' : ''}"\
202
+ " #{cfg['loop'] ? 'loop' : ''}"\
203
+ " controls>" \
204
+ " <source src=\"#{cfg['src']}\">" \
205
+ " Your browser doesn't support HTML5 video."\
206
+ " Here is a <a href=\"#{cfg['src']}\">link to download the video</a>"\
207
+ " instead."\
208
+ "</video>"
209
+ doc = Nokogiri::HTML(html)
210
+ return if element.parent.nil?
211
+ element.replace(doc.at('body').children.first)
188
212
  end
189
213
 
190
214
  def handle_iframe(element, data)
@@ -201,8 +225,9 @@ module Jekyll::Spaceship
201
225
  " frameborder=\"#{cfg['frameborder']}\""\
202
226
  " allowfullscreen>"\
203
227
  "</iframe>"
204
- doc = Nokogiri::XML(html)
205
- element.replace(doc.children.first)
228
+ doc = Nokogiri::HTML(html)
229
+ return if element.parent.nil?
230
+ element.replace(doc.at('body').children.first)
206
231
  end
207
232
 
208
233
  def get_id_from_html(url, pattern)
@@ -18,13 +18,21 @@ module Jekyll::Spaceship
18
18
  end
19
19
  if references.size > 0
20
20
  content.scan(/[^\n]*(?<!\\)\|[^\n]*/) do |result|
21
+ replace = result
21
22
  references.each do |key, val|
22
- replace = result.gsub(
23
- /\[([^\n\]]*?)\]\s*\[#{key}\]/,
24
- "[\1](#{val})")
25
- next if result == replace
26
- content = content.gsub(result, replace)
23
+ replace = replace.gsub(
24
+ /\[([^\n\]]*?)\]\s*\[#{Regexp.escape(key)}\]/,
25
+ "[\\1](#{val})"
26
+ )
27
27
  end
28
+ references.each do |key, val|
29
+ replace = replace.gsub(
30
+ /\[#{Regexp.escape(key)}\](?!\s*\(.*?\))/,
31
+ "[#{key}](#{val})"
32
+ )
33
+ end
34
+ next if result == replace
35
+ content = content.gsub(result, replace)
28
36
  end
29
37
  end
30
38
 
@@ -143,10 +151,10 @@ module Jekyll::Spaceship
143
151
  end
144
152
  end
145
153
 
146
- result = cell.content.match(/(\|)+$/)
154
+ result = cell.inner_html.match(/(\|)+$/)
147
155
  return if result.nil?
148
156
 
149
- cell.content = cell.content.gsub(/(\|)+$/, '')
157
+ cell.inner_html = cell.inner_html.gsub(/(\|)+$/, '')
150
158
  result = result[0]
151
159
  colspan = result.scan(/\|/).count
152
160
  scope.row.colspan += colspan
@@ -203,8 +211,8 @@ module Jekyll::Spaceship
203
211
 
204
212
  # handle rowspan
205
213
  span_cell = scope.table.span_row_cells[scope.row.col_index]
206
- if span_cell and cell.content.match(/^\s*\^{2}/)
207
- cell.content = cell.content.gsub(/^\s*\^{2}/, '')
214
+ if span_cell and cell.inner_html.match(/^\s*\^{2}/)
215
+ cell.inner_html = cell.inner_html.gsub(/^\s*\^{2}/, '')
208
216
  span_cell.inner_html += "\n<br>\n#{cell.inner_html}"
209
217
  rowspan = span_cell.get_attribute('rowspan') || 1
210
218
  rowspan = rowspan.to_i + 1
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Spaceship
5
- VERSION = "0.9.8"
5
+ VERSION = "0.9.9"
6
6
  end
7
7
  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.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeffreytse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-10 00:00:00.000000000 Z
11
+ date: 2021-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll