jekyll-spaceship 0.9.6 → 0.10.0

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: 917f5191110c86af367498a90d9ad362185254fdfc30f54eeb48705159b72db7
4
- data.tar.gz: 23e627f48d83363b2b473d2c080c98d327ddc51d982290209e218ff755a8920e
3
+ metadata.gz: 0e78e90266b5520e8f2779dea8af5f83b3bb4107d5666eac6dae98d2f754c88e
4
+ data.tar.gz: 2a485a89f512d3c1da45b52ba679f76575de7c91be34d687f2104984f286fb5f
5
5
  SHA512:
6
- metadata.gz: daf20ba10a46e6f8538a02b84153bb19f3371e4ea58b689f4c520a04eb7041e76f172ac5886fca2e8a6e9140515fc7afdb30afec97bdda38d99ed43df6ecb3e7
7
- data.tar.gz: '089e665d0359d9c0bfe0e37c1e91dfb63c6bc1dacc2c7f928e617c9d3cd1d8af959005a9cc70fca63f05a3ab5c662a24ac2ebaed113073483bc71676146bb12f'
6
+ metadata.gz: 6268083908d3ec0ff4420b13efd4b35acde48329d2339d7e793f29f0c2a8311f5d7aef36ec5fa95a5e2d94fe3cc04db8fb540f00a0e10f26335dcedb8da236de
7
+ data.tar.gz: 0b5d5950a8a446429cf4a00c3ebba32cde6068f4d3856e00f2868933cfa8031ef3af0b1bee0c5d40e28ea1abd19530a87b3addfd184a543ad27a3684ee10cb01
data/.github/FUNDING.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # These are supported funding model platforms
2
2
 
3
- github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
3
+ github: jeffreytse # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
4
  patreon: jeffreytse
5
5
  open_collective: # Replace with a single Open Collective username
6
6
  ko_fi: jeffreytse
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
 
@@ -5,7 +5,6 @@ module Jekyll::Spaceship
5
5
  CONFIG_NAME = 'jekyll-spaceship'
6
6
  DEFAULT_CONFIG = {
7
7
  'processors' => [
8
- 'cache-processor',
9
8
  'table-processor',
10
9
  'mathjax-processor',
11
10
  'plantuml-processor',
@@ -192,7 +192,9 @@ module Jekyll::Spaceship
192
192
  while @exclusion_store.size > 0
193
193
  match = @exclusion_store.pop
194
194
  id = @exclusion_store.size
195
- content = content.sub("<!JEKYLL@#{object_id}@#{id}>", match)
195
+ content = content.sub(
196
+ "<!JEKYLL@#{object_id}@#{id}>"
197
+ ) { match }
196
198
  end
197
199
  @exclusion_store = []
198
200
  content
@@ -16,31 +16,85 @@ module Jekyll::Spaceship
16
16
  end
17
17
 
18
18
  def on_handle_html(content)
19
- # handle emoji markup
20
- content.scan(/:([\w\d+-]+):/) do |match|
19
+ emoji_filter(content, 'pre code') do |emoji|
20
+ # mark current file has been handled
21
+ self.handled = true
22
+
23
+ # here is the replacement content
24
+ "<img class=\"#{config['css']['class']}\""\
25
+ " title=\":#{emoji.name}:\""\
26
+ " alt=\":#{emoji.name}:\""\
27
+ " raw=\"#{emoji.raw}\""\
28
+ " src=\"#{config['src']}#{emoji.image_filename}\""\
29
+ " style=\"vertical-align: middle; display: inline;"\
30
+ " max-width: 1em; visibility: hidden;\""\
31
+ " onload=\"this.style.visibility='visible'\""\
32
+ " onerror=\"this.replaceWith(this.getAttribute('raw'))\">"\
33
+ "</img>"
34
+ end
35
+ end
36
+
37
+ def emoji_filter(content, selector)
38
+ # use nokogiri to parse html
39
+ doc = Nokogiri::HTML(content)
40
+
41
+ body = doc.at('body')
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
+
47
+ # Count for restoration
48
+ escaped_count = 0
49
+
50
+ # filter nodes (pre, code)
51
+ body.css(selector).each do |node|
52
+ count = escaped_count
53
+
54
+ # handle emoji markup
55
+ inner_html = node.inner_html.gsub(
56
+ /(?<!\\):([\w\d+-]+?)(?<!\\):/
57
+ ) do |match|
58
+ escaped_count += 1
59
+ "\\:#{match[1..-2]}\\:"
60
+ end
61
+
62
+ if escaped_count > count
63
+ node.inner_html = inner_html
64
+ end
65
+ end
66
+
67
+ # parse the emoji
68
+ content = body.inner_html
69
+ content.scan(/(?<!\\):([\w\d+-]+?)(?<!\\):/) do |match|
70
+ # Skip invalid emoji name
21
71
  emoji = Emoji.find_by_alias match[0]
22
72
  next if emoji.nil?
23
- self.handled = true
24
73
 
25
74
  # escape plus sign
26
75
  emoji_name = emoji.name.gsub('+', '\\\+')
27
- css_class = self.config['css']['class']
76
+
77
+ result = yield emoji
78
+ next if result.nil?
28
79
 
29
80
  content = content.gsub(
30
81
  /(?<!\=")\s*:#{emoji_name}:\s*(?!"\s)/,
31
- "<img class=\"#{css_class}\""\
32
- " title=\":#{emoji.name}:\""\
33
- " alt=\":#{emoji.name}:\""\
34
- " raw=\"#{emoji.raw}\""\
35
- " src=\"#{config['src']}#{emoji.image_filename}\""\
36
- " style=\"vertical-align: middle; display: inline;"\
37
- " max-width: 1em; visibility: hidden;\""\
38
- " onload=\"this.style.visibility='visible'\""\
39
- " onerror=\"this.replaceWith(this.getAttribute('raw'))\">"\
40
- "</img>"
82
+ result)
83
+ end
84
+
85
+ body.inner_html = content
86
+
87
+ return doc.to_html if escaped_count.zero?
88
+
89
+ # restore nodes (pre, code)
90
+ body.css(selector).each do |node|
91
+ # handle emoji markup
92
+ node.inner_html = node.inner_html.gsub(
93
+ /\\:([\w\d+-]+?)\\:/, ':\1:'
41
94
  )
42
95
  end
43
- content
96
+
97
+ doc.to_html
44
98
  end
45
99
  end
46
100
  end
@@ -35,6 +35,8 @@ module Jekyll::Spaceship
35
35
  patterns['include'].each do |pattern|
36
36
  content.scan(pattern) do |result|
37
37
  expr = result[0]
38
+ body = result[1]
39
+ next if body.size.zero?
38
40
  is_excluded = false
39
41
  patterns['exclude'].each do |pe|
40
42
  break is_excluded = true if expr.match(/#{pe}/)
@@ -42,6 +44,7 @@ module Jekyll::Spaceship
42
44
  next if is_excluded
43
45
  escaped_expr = expr
44
46
  .gsub(/(?<!^)\\(?!\S$)/, '\\\\\\\\')
47
+ .gsub(/(?<!\\)\$\$/, '\\\$\\\$')
45
48
  .gsub(/\\ /, '\\\\\\ ')
46
49
  content = content.gsub(expr, escaped_expr)
47
50
  end
@@ -89,7 +92,7 @@ module Jekyll::Spaceship
89
92
  r&.each do |i|
90
93
  btag = Regexp.escape(i[0])
91
94
  etag = Regexp.escape(i[1])
92
- patterns <<= /((?<!\\\\)#{btag}.+?(?<!\\\\)#{etag})/
95
+ patterns <<= /((?<!\\\\)#{btag}(.*?)(?<!\\\\)#{etag})/
93
96
  end
94
97
  end
95
98
  end
@@ -104,20 +107,27 @@ module Jekyll::Spaceship
104
107
 
105
108
  def scan_mathjax_expression(doc, &block)
106
109
  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
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|
111
125
  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
126
  # check normal mathjax expression
119
127
  node.content.scan(pattern) do |result|
120
128
  expr = result[0]
129
+ body = result[1]
130
+ next if body.size.zero?
121
131
  is_excluded = false
122
132
  patterns['exclude'].each do |pe|
123
133
  break is_excluded = true if expr.match(/#{pe}/)
@@ -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)
@@ -60,6 +60,9 @@ module Jekyll::Spaceship
60
60
  end
61
61
 
62
62
  def handle_mermaid(code)
63
+ # Handle extra empty lines, otherwise it would cause error
64
+ code = code.gsub(/\n\s*\n/, "\n%%-\n")
65
+
63
66
  # encode to UTF-8
64
67
  code = code.encode('UTF-8')
65
68
  url = get_url(code)
@@ -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
 
@@ -87,7 +95,6 @@ module Jekyll::Spaceship
87
95
  handle_multi_rows(data)
88
96
  handle_text_align(data)
89
97
  handle_rowspan(data)
90
- handle_attr_list(data)
91
98
  end
92
99
  end
93
100
  rows.each do |row|
@@ -95,6 +102,7 @@ module Jekyll::Spaceship
95
102
  cells.each do |cell|
96
103
  data.cell = cell
97
104
  handle_format(data)
105
+ handle_attr_list(data)
98
106
  end
99
107
  end
100
108
  self.handled = true
@@ -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
@@ -264,7 +272,7 @@ module Jekyll::Spaceship
264
272
  content = cell.inner_html
265
273
  # inline attribute list(IAL) handler
266
274
  ial_handler = ->(list) do
267
- list.scan(/(\S+)=("|')(.*?)\2|(\S+)/) do |attr|
275
+ list.scan(/(\S+)=(”|"|')(.*?)\2|(\S+)/) do |attr|
268
276
  key = attr[0]
269
277
  val = attr[2]
270
278
  single = attr[3]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Spaceship
5
- VERSION = "0.9.6"
5
+ VERSION = "0.10.0"
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.6
4
+ version: 0.10.0
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-12-02 00:00:00.000000000 Z
11
+ date: 2021-08-28 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,