jekyll-spaceship 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});"
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
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Jekyll::Spaceship
4
4
  class PlantUMLProcessor < Processor
5
+ exclude :none
6
+
5
7
  def on_handle_markdown(content)
6
8
  # match default plantuml block and code block
7
9
  pattern = Regexp.union(
@@ -7,7 +7,7 @@ module Jekyll::Spaceship
7
7
  def on_handle_markdown(content)
8
8
  # escape ordered list.
9
9
  rexp = /(\s*)(?<!\\)\\(?=\d+\.)/
10
- self.handled = true if content.match?(rexp)
10
+ self.handled = true if content.match(rexp)
11
11
  content.gsub(rexp, '\1&#8291;')
12
12
  end
13
13
  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 = OpenStruct.new(_: OpenStruct.new)
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,65 @@ 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 scope_table.row != data.row
107
- scope_table.row = data.row
108
- scope_row.colspan = 0
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
- result = cell.content.match(/(\s*\|)+$/)
113
- if cell == cells.last and scope_row.colspan > 0
114
- range = (cells.count - scope_row.colspan)...cells.count
115
+ if cell == cells.last and scope.row.colspan > 0
116
+ range = (cells.count - scope.row.colspan)...cells.count
115
117
  for i in range do
116
118
  cells[i].remove
117
119
  end
118
120
  end
119
- if result
120
- result = result[0]
121
- scope_row.colspan += result.scan(/\|/).count
122
- cell.content = cell.content.gsub(/(\s*\|)+$/, '')
123
- cell.set_attribute('colspan', scope_row.colspan + 1)
124
- end
121
+
122
+ result = cell.content.match(/(\s*\|)+$/)
123
+ return if result.nil?
124
+
125
+ cell.content = cell.content.gsub(/(\s*\|)+$/, '')
126
+ result = result[0]
127
+ colspan = result.scan(/\|/).count
128
+ scope.row.colspan += colspan
129
+ cell.set_attribute('colspan', colspan + 1)
125
130
  end
126
131
 
127
132
  def handle_multi_rows(data)
128
133
  scope = data.scope.call __method__
129
- scope_table = scope.table
130
134
  cells = data.cells
131
135
  row = data.row
132
136
  cell = data.cell
133
137
 
134
- if scope_table.table != data.table
135
- scope_table.table = data.table
136
- scope_table.multi_row_cells = nil
137
- scope_table.multi_row_start = false
138
+ if scope.table.table != data.table
139
+ scope.table.table = data.table
140
+ scope.table.multi_row_cells = nil
141
+ scope.table.multi_row_start = false
138
142
  end
139
143
 
140
144
  # handle multi-rows
@@ -143,41 +147,38 @@ module Jekyll::Spaceship
143
147
  match = cell.content.match(/(?<!\\)\\\s*$/)
144
148
  if match
145
149
  cell.content = cell.content.gsub(/(?<!\\)\\\s*$/, '')
146
- if not scope_table.multi_row_start
147
- scope_table.multi_row_cells = cells
148
- scope_table.multi_row_start = true
150
+ if not scope.table.multi_row_start
151
+ scope.table.multi_row_cells = cells
152
+ scope.table.multi_row_start = true
149
153
  end
150
154
  end
151
155
 
152
- if scope_table.multi_row_cells != cells and scope_table.multi_row_start
153
- for i in 0...scope_table.multi_row_cells.count do
154
- multi_row_cell = scope_table.multi_row_cells[i]
156
+ if scope.table.multi_row_cells != cells and scope.table.multi_row_start
157
+ for i in 0...scope.table.multi_row_cells.count do
158
+ multi_row_cell = scope.table.multi_row_cells[i]
155
159
  multi_row_cell.content += " \n#{cells[i].content}"
156
160
  end
157
161
  row.remove
158
162
  end
159
- scope_table.multi_row_start = false if not match
163
+ scope.table.multi_row_start = false if not match
160
164
  end
161
165
 
162
166
  def handle_rowspan(data)
163
167
  scope = data.scope.call __method__
164
- scope_table = scope.table
165
- scope_row = scope.row
166
168
  cell = data.cell
167
169
  cells = data.cells
168
170
 
169
- if scope_table.table != data.table
170
- scope_table.table = data.table
171
- scope_table.span_row_cells = []
171
+ if scope.table.table != data.table
172
+ scope.table.table = data.table
173
+ scope.table.span_row_cells = []
172
174
  end
173
-
174
- if scope_row.row != data.row
175
- scope_row.row = data.row
176
- scope_row.col_index = 0
175
+ if scope.row.row != data.row
176
+ scope.row.row = data.row
177
+ scope.row.col_index = 0
177
178
  end
178
179
 
179
180
  # handle rowspan
180
- span_cell = scope_table.span_row_cells[scope_row.col_index]
181
+ span_cell = scope.table.span_row_cells[scope.row.col_index]
181
182
  if span_cell and cell.content.match(/^\s*\^{2}/)
182
183
  cell.content = cell.content.gsub(/^\s*\^{2}/, '')
183
184
  span_cell.content += " \n#{cell.content}"
@@ -186,10 +187,9 @@ module Jekyll::Spaceship
186
187
  span_cell.set_attribute('rowspan', "#{rowspan}")
187
188
  cell.remove
188
189
  else
189
- scope_table.span_row_cells[scope_row.col_index] = cell
190
+ scope.table.span_row_cells[scope.row.col_index] = cell
190
191
  end
191
-
192
- scope_row.col_index += 1
192
+ scope.row.col_index += [cell.get_attribute('colspan').to_i, 1].max
193
193
  end
194
194
 
195
195
  def handle_text_align(data)
@@ -211,7 +211,6 @@ module Jekyll::Spaceship
211
211
 
212
212
  # handle text align
213
213
  return if align == 0
214
-
215
214
  style = cell.get_attribute('style')
216
215
  if align == 1
217
216
  align = 'text-align: left'
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'uri'
4
+
3
5
  module Jekyll::Spaceship
4
6
  class VideoProcessor < Processor
5
7
  def on_handle_markdown(content)
@@ -70,20 +72,26 @@ module Jekyll::Spaceship
70
72
  url = match_data[2]
71
73
  id = match_data[4]
72
74
  title = match_data[6]
73
- width = url.match(/(?<=width=)(\S*?)(?=&|$)/)
74
- height = url.match(/(?<=height=)(\S*?)(?=&|$)/)
75
+ qs = url.match(/(?<=\?)(\S*?)$/)
76
+ qs = Hash[URI.decode_www_form(qs.to_s)].reject do |k, v|
77
+ next true if v == id or v == ''
78
+ end
79
+
80
+ width = qs['width'] || data[:width] || 600
81
+ height = qs['height'] || data[:height] || 400
82
+ style = "max-width: 100%" if width.nil?
75
83
 
76
- data[:width] = 600 if data[:width].nil?
77
- data[:height] = 400 if data[:height].nil?
78
- width = data[:width] if width.nil?
79
- height = data[:height] if height.nil?
84
+ url = URI("#{iframe_url}#{id}").tap do |v|
85
+ v.query = URI.encode_www_form(qs) if qs.size > 0
86
+ end
80
87
 
81
- url = "#{iframe_url}#{id}"
82
88
  html = "<iframe \
83
89
  src=\"#{url}\" \
84
90
  title=\"#{title}\" \
85
91
  width=\"#{width}\" \
86
92
  height=\"#{height}\" \
93
+ style=\"#{style}\" \
94
+ allow=\"autoplay; encrypted-media\" \
87
95
  frameborder=\"0\" \
88
96
  allowfullscreen=\"\">\
89
97
  </iframe>"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Spaceship
5
- VERSION = "0.4.0"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
@@ -0,0 +1,6 @@
1
+ #! /bin/bash
2
+
3
+ set -e
4
+
5
+ script/test
6
+ bundle exec rake build
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+ set -ex
3
+
4
+ bundle exec rspec "$@"
metadata CHANGED
@@ -1,57 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-spaceship
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeffreytse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-28 00:00:00.000000000 Z
11
+ date: 2020-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: nokogiri
14
+ name: jekyll
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '3.6'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '1.6'
29
+ version: '3.6'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
27
33
  - !ruby/object:Gem::Dependency
28
- name: jekyll
34
+ name: nokogiri
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '3.7'
34
- type: :development
39
+ version: '1.6'
40
+ type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
44
  - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: '3.7'
46
+ version: '1.6'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: bundler
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - "~>"
51
+ - - ">="
46
52
  - !ruby/object:Gem::Version
47
- version: '1.10'
53
+ version: '0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - "~>"
58
+ - - ">="
53
59
  - !ruby/object:Gem::Version
54
- version: '1.10'
60
+ version: '0'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: rake
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -87,15 +93,22 @@ executables: []
87
93
  extensions: []
88
94
  extra_rdoc_files: []
89
95
  files:
96
+ - ".codeclimate.yml"
97
+ - ".github/FUNDING.yml"
90
98
  - ".gitignore"
99
+ - ".travis.yml"
91
100
  - Gemfile
92
101
  - LICENSE.txt
93
102
  - README.md
103
+ - Rakefile
94
104
  - jekyll-spaceship.gemspec
95
105
  - lib/jekyll-spaceship.rb
96
106
  - lib/jekyll-spaceship/cores/logger.rb
107
+ - lib/jekyll-spaceship/cores/manager.rb
97
108
  - lib/jekyll-spaceship/cores/processor.rb
98
109
  - lib/jekyll-spaceship/cores/register.rb
110
+ - lib/jekyll-spaceship/cores/type.rb
111
+ - lib/jekyll-spaceship/processors/emoji-processor.rb
99
112
  - lib/jekyll-spaceship/processors/mathjax-processor.rb
100
113
  - lib/jekyll-spaceship/processors/plantuml-processor.rb
101
114
  - lib/jekyll-spaceship/processors/polyfill-processor.rb
@@ -103,6 +116,9 @@ files:
103
116
  - lib/jekyll-spaceship/processors/video-processor.rb
104
117
  - lib/jekyll-spaceship/utils/plantuml/plantuml.jar
105
118
  - lib/jekyll-spaceship/version.rb
119
+ - logos/jekyll-spaceship-logo.png
120
+ - script/cibuild
121
+ - script/test
106
122
  homepage: https://github.com/jeffreytse/jekyll-spaceship
107
123
  licenses:
108
124
  - MIT
@@ -122,9 +138,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
138
  - !ruby/object:Gem::Version
123
139
  version: '0'
124
140
  requirements: []
125
- rubygems_version: 3.0.6
141
+ rubyforge_project:
142
+ rubygems_version: 2.7.7
126
143
  signing_key:
127
144
  specification_version: 4
128
145
  summary: A Jekyll plugin to provide powerful supports for table, mathjax, plantuml,
129
- youtube, etc.
146
+ emoji, youtube, vimeo, dailymotion, etc.
130
147
  test_files: []