jekyll-spaceship 0.8.3 → 0.9.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: c2a6f219ec49d2767f11891946203051ed55b82567d0021c929eb1831769e246
4
- data.tar.gz: 80bdf4869aaf201752f791031b6730b0d3e86681cdb246f4855db960ec913a60
3
+ metadata.gz: c6ae47db0fb8b3515463a5703cdbfa2c596262066b0af602e3d7f82360872c78
4
+ data.tar.gz: 9f4c96c07fe26d5b1e9a44338375a29470d528e2375902d9e7198cfe377d0b26
5
5
  SHA512:
6
- metadata.gz: b7ff25fd47603c5f3471db4d33cad716956ee41918fa5408fae35176025658122ee4cc567db6a68675d4c1e677d9f7b50a0e32ce12fb0eae1a3e8525503be8f0
7
- data.tar.gz: ca6a2e4071c8eac5f8759778bb2c0e228a3b94369c16815fb150e8041b685a11e60f18dcd7f05afae3e9fbcf8075b5bfb61046248ff440b5dbefb80cedcef02e
6
+ metadata.gz: 7a24363b63096f27c60c92aa0ad37561cf230ae6e61c0e49b7c556e9a584c1ffddc388cf3ab3cb424382351d55a30439628f6a909e93aae4cfce51363f8ffd0f
7
+ data.tar.gz: 297d038c14a9bdb8b856b414eaefba93232ff82518a3c01eaf97ac98f2dd1792d6d875a140e5f30497dbcb759f4e59a6ea6632c64c186f0acacfb249152b2c3e
data/README.md CHANGED
@@ -101,6 +101,7 @@ Spaceship is a minimalistic, powerful and extremely customizable [Jekyll](https:
101
101
  - [1.3 Headerless](#headerless)
102
102
  - [1.4 Cell Alignment](#cell-alignment)
103
103
  - [1.5 Cell Markdown](#cell-markdown)
104
+ - [1.6 Cell Inline Attributes](#cell-inline-attributes)
104
105
  - [2. MathJax Usage](#2-mathjax-usage)
105
106
  - [2.1 Performance Optimization](#21-performance-optimization)
106
107
  - [2.2 How to use?](#22-how-to-use)
@@ -165,12 +166,16 @@ jekyll-spaceship:
165
166
  - emoji-processor
166
167
  - element-processor
167
168
  mathjax-processor:
168
- src: //cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
169
+ src:
170
+ - https://polyfill.io/v3/polyfill.min.js?features=es6
171
+ - https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
169
172
  config:
170
- tex2jax:
173
+ tex:
171
174
  inlineMath:
172
175
  - ['$','$']
173
176
  - ['\(','\)']
177
+ svg:
178
+ fontCache: 'global'
174
179
  plantuml-processor:
175
180
  mode: default # mode value 'pre-fetch' for fetching image at building stage
176
181
  css:
@@ -534,6 +539,61 @@ Rowspan is 4
534
539
  </tbody>
535
540
  </table>
536
541
 
542
+ #### Cell Inline Attributes
543
+
544
+ This feature is very useful for custom cell such as using inline style. (e.g., background, color, font)
545
+ The idea and syntax comes from the [Maruku](http://maruku.rubyforge.org/) package.
546
+
547
+ [](https://kramdown.gettalong.org/syntax.html#block-ials)
548
+
549
+ Following are some examples of attributes definitions (ALDs) and afterwards comes the syntax explanation:
550
+
551
+ ```markdown
552
+ {:ref-name: #id .cls1 .cls2}
553
+ {:second: ref-name #id-of-other title="hallo you"}
554
+ {:other: ref-name second}
555
+ ```
556
+
557
+ An ALD line has the following structure:
558
+
559
+ - a left brace, optionally preceded by up to three spaces,
560
+ - followed by a colon, the id and another colon,
561
+ - followed by attribute definitions (allowed characters are backslash-escaped closing braces or any character except a not escaped closing brace),
562
+ - followed by a closing brace and optional spaces until the end of the line.
563
+
564
+ If there is more than one ALD with the same reference name, the attribute definitions of all the ALDs are processed like they are defined in one ALD.
565
+
566
+ An inline attribute list (IAL) is used to attach attributes to another element.
567
+ Here are some examples for span IALs:
568
+
569
+ ```markdown
570
+ {: #id .cls1 .cls2} <!-- #id <=> id="id", .cls1 .cls2 <=> class="cls1 cls2" -->
571
+ {: ref-name title="hallo you"}
572
+ {: ref-name class='.cls3' .cls4}
573
+ ```
574
+
575
+ Here is an example for custom table cell with IAL:
576
+
577
+ ```markdown
578
+ {:color-style: style="background: black;"}
579
+ {:color-style: style="color: white;"}
580
+ {:text-style: style="font-weight: 800; text-decoration: underline;"}
581
+
582
+ |: Here's an Inline Attribute Lists example :||||
583
+ | ------- | ------------------ | -------------------- | ------------------ |
584
+ |: :|: <div style="color: red;"> &lt; Normal HTML Block > </div> :|||
585
+ | ^^ | Red {: .cls style="background: orange" } |||
586
+ | ^^ IALs | Green {: #id style="background: green; color: white" } |||
587
+ | ^^ | Blue {: style="background: blue; color: white" } |||
588
+ | ^^ | Black {: color-style text-style } |||
589
+ ```
590
+
591
+ Code above would be parsed as:
592
+
593
+ <img width="580px" src="https://user-images.githubusercontent.com/9413601/88461592-738afb00-ced7-11ea-9aac-3179023742b0.png" alt="IALs">
594
+
595
+ Additionally, [here](https://kramdown.gettalong.org/syntax.html#block-ials) you can learn more details about IALs.
596
+
537
597
  ### 2. MathJax Usage
538
598
 
539
599
  [MathJax](http://www.mathjax.org/) is an open-source JavaScript display engine for LaTeX, MathML, and AsciiMath notation that works in all modern browsers.
@@ -69,7 +69,7 @@ module Jekyll::Spaceship
69
69
  end
70
70
 
71
71
  def self.ext(page)
72
- ext = page.path.match(/\.\S+$/)
72
+ ext = page.path.match(/\.[^.]+$/)
73
73
  ext.to_s.rstrip
74
74
  end
75
75
 
@@ -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, :math
68
+ self.class.exclude :code, :math, :liquid_filter
69
69
  end
70
70
  @exclusions = @@_exclusions.uniq
71
71
  @@_exclusions.clear
@@ -121,7 +121,7 @@ module Jekyll::Spaceship
121
121
  else
122
122
  if Type.html? output_ext
123
123
  method = 'on_handle_html'
124
- elsif css? output_ext
124
+ elsif Type.css? output_ext
125
125
  method = 'on_handle_css'
126
126
  end
127
127
  if self.respond_to? method
@@ -156,15 +156,17 @@ module Jekyll::Spaceship
156
156
  @exclusions.each do |type|
157
157
  regex = nil
158
158
  if type == :code
159
- regex = /((`+)\s*(\w*)((?:.|\n)*?)\2)/
159
+ regex = /(((?<!\\)`+)\s*(\w*)((?:.|\n)*?)\2)/
160
160
  elsif type == :math
161
161
  regex = /(((?<!\\)\${1,2})[^\n]*?\1)/
162
+ elsif type == :liquid_filter
163
+ regex = /((?<!\\)((\{\{[^\n]*?\}\})|(\{%[^\n]*?%\})))/
162
164
  end
163
165
  next if regex.nil?
164
166
  content.scan(regex) do |match_data|
165
167
  match = match_data[0]
166
168
  id = @exclusion_store.size
167
- content = content.sub(match, "[JEKYLL@#{object_id}@#{id}]")
169
+ content = content.sub(match, "<!JEKYLL@#{object_id}@#{id}>")
168
170
  @exclusion_store.push match
169
171
  end
170
172
  end
@@ -175,7 +177,7 @@ module Jekyll::Spaceship
175
177
  while @exclusion_store.size > 0
176
178
  match = @exclusion_store.pop
177
179
  id = @exclusion_store.size
178
- content = content.sub("[JEKYLL@#{object_id}@#{id}]", match)
180
+ content = content.sub("<!JEKYLL@#{object_id}@#{id}>", match)
179
181
  end
180
182
  @exclusion_store = []
181
183
  content
@@ -24,15 +24,16 @@ module Jekyll::Spaceship
24
24
 
25
25
  # escape plus sign
26
26
  emoji_name = emoji.name.gsub('+', '\\\+')
27
+ css_class = self.config['css']['class']
27
28
 
28
29
  content = content.gsub(
29
30
  /(?<!\=")\s*:#{emoji_name}:\s*(?!"\s)/,
30
- "<img class=\"\""\
31
+ "<img class=\"#{css_class}\""\
31
32
  " title=\":#{emoji.name}:\""\
32
33
  " alt=\":#{emoji.name}:\""\
33
34
  " raw=\"#{emoji.raw}\""\
34
35
  " src=\"#{config['src']}#{emoji.image_filename}\""\
35
- " style=\"vertical-align: middle;"\
36
+ " style=\"vertical-align: middle; display: inline;"\
36
37
  " max-width: 1em; visibility: hidden;\""\
37
38
  " onload=\"this.style.visibility='visible'\""\
38
39
  " onerror=\"this.replaceWith(this.getAttribute('raw'))\">"\
@@ -6,9 +6,13 @@ module Jekyll::Spaceship
6
6
  class MathjaxProcessor < Processor
7
7
  def self.config
8
8
  {
9
- 'src' => '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML',
9
+ 'src' => [
10
+ 'https://polyfill.io/v3/polyfill.min.js?features=es6',
11
+ 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js',
12
+ ],
10
13
  'config' => {
11
- 'tex2jax' => { 'inlineMath' => [['$','$'], ['\\(','\\)']] }
14
+ 'tex' => { 'inlineMath' => [['$','$'], ['\\(','\\)']] },
15
+ 'svg': { 'fontCache': 'global' }
12
16
  }
13
17
  }
14
18
  end
@@ -27,8 +31,15 @@ module Jekyll::Spaceship
27
31
 
28
32
  self.handled = true
29
33
 
30
- cfg = "MathJax.Hub.Config(#{config['config'].to_json});"
31
- head.add_child("<script src=\"#{config['src']}\">#{cfg}</script>")
34
+ # add mathjax config
35
+ cfg = config['config'].to_json
36
+ head.add_child("<script>MathJax=#{cfg}</script>")
37
+
38
+ # add mathjax dependencies
39
+ config['src'] = [config['src']] if config['src'].is_a? String
40
+ config['src'].each do |src|
41
+ head.add_child("<script src=\"#{src}\"></script>")
42
+ end
32
43
 
33
44
  doc.to_html
34
45
  end
@@ -5,6 +5,9 @@ require "nokogiri"
5
5
 
6
6
  module Jekyll::Spaceship
7
7
  class TableProcessor < Processor
8
+ ATTR_LIST_PATTERN = /((?<!\\)\{:(?:([A-Za-z]\S*):)?(.*?)(?<!\\)\})/
9
+ ATTR_LIST_REFS = {}
10
+
8
11
  def on_handle_markdown(content)
9
12
  # pre-handle reference-style links
10
13
  references = {}
@@ -16,7 +19,9 @@ module Jekyll::Spaceship
16
19
  if references.size > 0
17
20
  content.scan(/[^\n]*(?<!\\)\|[^\n]*/) do |result|
18
21
  references.each do |key, val|
19
- replace = result.gsub(/\[([^\n]*)\]\s*\[#{key}\]/, "[\1](#{val})")
22
+ replace = result.gsub(
23
+ /\[([^\n\]]*?)\]\s*\[#{key}\]/,
24
+ "[\1](#{val})")
20
25
  next if result == replace
21
26
  content = content.gsub(result, replace)
22
27
  end
@@ -42,6 +47,19 @@ module Jekyll::Spaceship
42
47
  next if result == replace
43
48
  content = content.gsub(result, replace)
44
49
  end
50
+
51
+ # pre-handle attribute list (AL)
52
+ ATTR_LIST_REFS.clear()
53
+ content.scan(ATTR_LIST_PATTERN) do |result|
54
+ ref = result[1]
55
+ list = result[2]
56
+ next if ref.nil?
57
+ if ATTR_LIST_REFS.has_key? ref
58
+ ATTR_LIST_REFS[ref] += list
59
+ else
60
+ ATTR_LIST_REFS[ref] = list
61
+ end
62
+ end
45
63
  content
46
64
  end
47
65
 
@@ -69,6 +87,7 @@ module Jekyll::Spaceship
69
87
  handle_multi_rows(data)
70
88
  handle_text_align(data)
71
89
  handle_rowspan(data)
90
+ handle_attr_list(data)
72
91
  end
73
92
  end
74
93
  rows.each do |row|
@@ -161,7 +180,7 @@ module Jekyll::Spaceship
161
180
  if scope.table.multi_row_cells != cells and scope.table.multi_row_start
162
181
  for i in 0...scope.table.multi_row_cells.count do
163
182
  multi_row_cell = scope.table.multi_row_cells[i]
164
- multi_row_cell.inner_html += "<br>#{cells[i].inner_html}"
183
+ multi_row_cell.inner_html += "\n<br>\n#{cells[i].inner_html}"
165
184
  end
166
185
  row.remove
167
186
  end
@@ -186,7 +205,7 @@ module Jekyll::Spaceship
186
205
  span_cell = scope.table.span_row_cells[scope.row.col_index]
187
206
  if span_cell and cell.content.match(/^\s*\^{2}/)
188
207
  cell.content = cell.content.gsub(/^\s*\^{2}/, '')
189
- span_cell.inner_html += "<br>#{cell.inner_html}"
208
+ span_cell.inner_html += "\n<br>\n#{cell.inner_html}"
190
209
  rowspan = span_cell.get_attribute('rowspan') || 1
191
210
  rowspan = rowspan.to_i + 1
192
211
  span_cell.set_attribute('rowspan', "#{rowspan}")
@@ -235,6 +254,52 @@ module Jekyll::Spaceship
235
254
  cell.set_attribute('style', style)
236
255
  end
237
256
 
257
+ # Examples:
258
+ # {:ref-name: .cls1 title="hello" }
259
+ # {: #id ref-name data="world" }
260
+ # {: #id title="hello" }
261
+ # {: .cls style="color: #333" }
262
+ def handle_attr_list(data)
263
+ cell = data.cell
264
+ content = cell.inner_html
265
+ # inline attribute list(IAL) handler
266
+ ial_handler = ->(list) do
267
+ list.scan(/(\S+)=("|')(.*?)\2|(\S+)/) do |attr|
268
+ key = attr[0]
269
+ val = attr[2]
270
+ single = attr[3]
271
+ if !key.nil?
272
+ val = (cell.get_attribute(key) || '') + val
273
+ cell.set_attribute(key, val)
274
+ elsif !single.nil?
275
+ if single.start_with? '#'
276
+ key = 'id'
277
+ val = single[1..-1]
278
+ elsif single.start_with? '.'
279
+ key = 'class'
280
+ val = cell.get_attribute(key) || ''
281
+ val += (val.size.zero? ? '' : ' ') + single[1..-1]
282
+ elsif ATTR_LIST_REFS.has_key? single
283
+ ial_handler.call ATTR_LIST_REFS[single]
284
+ end
285
+ unless key.nil?
286
+ cell.set_attribute(key, val)
287
+ end
288
+ end
289
+ end
290
+ end
291
+ # handle attribute list
292
+ content.scan(ATTR_LIST_PATTERN) do |result|
293
+ ref = result[1]
294
+ list = result[2]
295
+ # handle inline attribute list
296
+ ial_handler.call list if ref.nil?
297
+ # remove attr_list
298
+ content = content.sub(result[0], '')
299
+ end
300
+ cell.inner_html = content
301
+ end
302
+
238
303
  def handle_format(data)
239
304
  cell = data.cell
240
305
  cvter = self.converter('markdown')
@@ -242,8 +307,14 @@ module Jekyll::Spaceship
242
307
  content = cell.inner_html
243
308
  .gsub(/(?<!\\)\|/, '\\|')
244
309
  .gsub(/^\s+|\s+$/, '')
310
+ .gsub(/&lt;/, '<')
311
+ .gsub(/&gt;/, '>')
245
312
  content = cvter.convert(content)
246
- cell.inner_html = Nokogiri::HTML.fragment(content)
313
+ content = Nokogiri::HTML.fragment(content)
314
+ if content.children.first&.name == 'p'
315
+ content = content.children
316
+ end
317
+ cell.inner_html = content.inner_html
247
318
  end
248
319
  end
249
320
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Spaceship
5
- VERSION = "0.8.3"
5
+ VERSION = "0.9.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.8.3
4
+ version: 0.9.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-07-04 00:00:00.000000000 Z
11
+ date: 2020-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -169,8 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  - !ruby/object:Gem::Version
170
170
  version: '0'
171
171
  requirements: []
172
- rubyforge_project:
173
- rubygems_version: 2.7.7
172
+ rubygems_version: 3.0.8
174
173
  signing_key:
175
174
  specification_version: 4
176
175
  summary: A Jekyll plugin to provide powerful supports for table, mathjax, plantuml,