jekyll-spaceship 0.8.1 → 0.8.2

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: 03c21c812a08651efca92f4b47b56249235da50b32b9d3eecb53dc3900d4e96a
4
- data.tar.gz: abe8bcef58bcf94b21d9817fd502f05d6f603b0861dcb553b112a0c976a5be9b
3
+ metadata.gz: 419f539c81e8313699cf1e0798cdffe004a0f04f53845f3d72f6f7df18b072ed
4
+ data.tar.gz: bad98cd8ba939cf7c370841f12f4d56b01d78df306cb7e5143f68a8f53055123
5
5
  SHA512:
6
- metadata.gz: f0ee89b992667b27dbd9aacc6b094fa4572c2cf6d97f9fe7d90577a3615af5b571af29dae255cf6d493b122c9eaa5af6ee2c5aa95c7ad6589acbecb133ef51b9
7
- data.tar.gz: 19effd2d66e6684a6cd8c8e784262f354ef26cefa1bd1a2cb97411e7f9f97cf9081c2acc350ac3bb2978c31889ad62ede73dd05616d7659ac6d6019ceb6a51e6
6
+ metadata.gz: d3973afe5641351d205e473ba2ae3f61bb9daf14aab803602fe6b0e94dc8cf0f14603f09e5f0704f94612e9bcd65deec972d5b5567840ee63c822bb62fe80f8f
7
+ data.tar.gz: 647e60a7b13b26ea6053dc184f440d971aa4055a70ef7d6dc4d661061b513a28012f9815676f2ad75cd04030023e6d0dd3f4330336c0e6304d9fa7fe53279603
@@ -65,7 +65,7 @@ module Jekyll::Spaceship
65
65
 
66
66
  def initialize_exclusions
67
67
  if @@_exclusions.size.zero?
68
- self.class.exclude :code, :block_quotes
68
+ self.class.exclude :code, :math
69
69
  end
70
70
  @exclusions = @@_exclusions.uniq
71
71
  @@_exclusions.clear
@@ -157,6 +157,8 @@ module Jekyll::Spaceship
157
157
  regex = nil
158
158
  if type == :code
159
159
  regex = /((`+)\s*(\w*)((?:.|\n)*?)\2)/
160
+ elsif type == :math
161
+ regex = /(?<=^|\n)[^\n\|]*(((?<!\\)\${1,2})[^\n]*\2)[^\n\|]*/
160
162
  end
161
163
  next if regex.nil?
162
164
  content.scan(regex) do |match_data|
@@ -45,61 +45,11 @@ module Jekyll::Spaceship
45
45
  if data.kind_of? String
46
46
  element.replace Nokogiri::HTML.fragment(data)
47
47
  elsif data.kind_of? Hash
48
- # set name
49
- element.name = data['name'] unless data['name'].nil?
50
-
51
- # set props
52
- data['props']&.each do |prop, val|
53
- next element.remove_attribute if val.nil?
54
- if val.kind_of? Array
55
- next if val.size != 2
56
- v = element[prop]
57
- v = '' if v.nil?
58
- val = v.sub(/#{val[0]}/, val[1])
59
- elsif val.kind_of? Hash
60
- result = []
61
- val.each { |k, v| result.push "#{k}: #{v}" }
62
- val = result.join(";")
63
- end
64
- element.set_attribute(prop, val)
65
- end
66
-
67
- # processing children
68
- return unless data.has_key?('children')
69
- return element.inner_html = "" if data['children'].nil?
70
- children = self.create_children({
48
+ handle_hash_element({
71
49
  :doc => doc,
72
- :data => data['children']
50
+ :element => element,
51
+ :data => data,
73
52
  })
74
-
75
- # replace whole inner html
76
- unless data['children'].kind_of? Array
77
- return element.inner_html = children
78
- end
79
-
80
- if element.children.size.zero?
81
- return element.inner_html = children
82
- end
83
-
84
- index = data['children'].index(nil)
85
- if index.nil?
86
- return element.inner_html = children
87
- end
88
-
89
- # insert to the end of children
90
- if index == 0
91
- return element.children.last.after(children)
92
- end
93
-
94
- # insert to the begin of children
95
- rindex = data['children'].rindex { |item| !item.nil? }
96
- if index == rindex + 1
97
- return element.children.first.before children
98
- end
99
-
100
- # wrap the children
101
- element.children.first.before children[0..index]
102
- element.children.last.after children[index..children.size]
103
53
  end
104
54
  end
105
55
 
@@ -126,6 +76,45 @@ module Jekyll::Spaceship
126
76
  root.children
127
77
  end
128
78
 
79
+ def handle_hash_element(data)
80
+ doc = data[:doc]
81
+ element = data[:element]
82
+ data = data[:data]
83
+
84
+ # set name
85
+ element.name = data['name'] unless data['name'].nil?
86
+
87
+ # set props
88
+ data['props']&.each do |prop, val|
89
+ next element.remove_attribute if val.nil?
90
+ if val.kind_of? Array
91
+ next if val.size != 2
92
+ v = element[prop]
93
+ v = '' if v.nil?
94
+ val = v.sub(/#{val[0]}/, val[1])
95
+ elsif val.kind_of? Hash
96
+ result = []
97
+ val.each { |k, v| result.push "#{k}: #{v}" }
98
+ val = result.join(";")
99
+ end
100
+ element.set_attribute(prop, val)
101
+ end
102
+
103
+ # processing children
104
+ return unless data.has_key?('children')
105
+ return element.inner_html = "" if data['children'].nil?
106
+ children = self.create_children({
107
+ :doc => doc,
108
+ :data => data['children']
109
+ })
110
+
111
+ handle_element_placement({
112
+ :data => data,
113
+ :element => element,
114
+ :children => children,
115
+ })
116
+ end
117
+
129
118
  def create_element(data)
130
119
  doc = data[:doc]
131
120
  data = data[:data]
@@ -148,5 +137,34 @@ module Jekyll::Spaceship
148
137
  end
149
138
  node
150
139
  end
140
+
141
+ def handle_element_placement(data)
142
+ element = data[:element]
143
+ children = data[:children]
144
+ data = data[:data]
145
+
146
+ # replace whole inner html
147
+ unless data['children'].kind_of? Array
148
+ return element.inner_html = children
149
+ end
150
+
151
+ if element.children.size.zero?
152
+ return element.inner_html = children
153
+ end
154
+
155
+ index = data['children'].index(nil)
156
+ rindex = data['children'].rindex { |item| !item.nil? }
157
+
158
+ if index.nil?
159
+ element.inner_html = children
160
+ elsif index == 0 # insert to the end of children
161
+ element.children.last.after(children)
162
+ elsif index == rindex + 1 # insert to the begin of children
163
+ element.children.first.before children
164
+ else # wrap the children
165
+ element.children.first.before children[0..index]
166
+ element.children.last.after children[index..children.size]
167
+ end
168
+ end
151
169
  end
152
170
  end
@@ -14,9 +14,9 @@ module Jekyll::Spaceship
14
14
  references[ref_name] = ref_value
15
15
  end
16
16
  if references.size > 0
17
- content.scan(/.*(?<!\\)\|.*/) do |result|
17
+ content.scan(/[^\n]*(?<!\\)\|[^\n]*/) do |result|
18
18
  references.each do |key, val|
19
- replace = result.gsub(/\[(.*)\]\s*\[#{key}\]/, "[\1](#{val})")
19
+ replace = result.gsub(/\[([^\n]*)\]\s*\[#{key}\]/, "[\1](#{val})")
20
20
  next if result == replace
21
21
  content = content.gsub(result, replace)
22
22
  end
@@ -24,15 +24,15 @@ module Jekyll::Spaceship
24
24
  end
25
25
 
26
26
  # pre-handle row-span
27
- content = content.gsub(/(?<!\\)(\|.*\\\s*)\|\s*\n/, "\\1\n")
27
+ content = content.gsub(/(?<!\\)(\|[^\n]*\\\s*)\|\s*\n/, "\\1\n")
28
28
 
29
29
  # escape | and :
30
30
  content = content.gsub(/\|(?=\|)/, '\\|')
31
- .gsub(/\\:(?=.*?(?<!\\)\|)/, '\\\\\\\\:')
32
- .gsub(/((?<!\\)\|.*?)(\\:)/, '\1\\\\\\\\:')
31
+ .gsub(/\\:(?=[^\n]*?(?<!\\)\|)/, '\\\\\\\\:')
32
+ .gsub(/((?<!\\)\|[^\n]*?)(\\:)/, '\1\\\\\\\\:')
33
33
 
34
34
  # escape * and _ and $ etc.
35
- content.scan(/.*(?<!\\)\|.*/) do |result|
35
+ content.scan(/[^\n]*(?<!\\)\|[^\n]*/) do |result|
36
36
  replace = result.gsub(
37
37
  /(?<!(?<!\\)\\)(\*|\$|\[|\(|\"|_)/,
38
38
  '\\\\\\\\\1')
@@ -50,6 +50,7 @@ module Jekyll::Spaceship
50
50
 
51
51
  # handle each table
52
52
  doc.css('table').each do |table|
53
+ next if table.ancestors('code, pre').size > 0
53
54
  rows = table.css('tr')
54
55
  data.table = table
55
56
  data.rows = rows
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Spaceship
5
- VERSION = "0.8.1"
5
+ VERSION = "0.8.2"
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.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeffreytse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-25 00:00:00.000000000 Z
11
+ date: 2020-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll