jekyll-spaceship 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +153 -3
- data/jekyll-spaceship.gemspec +1 -1
- data/lib/jekyll-spaceship/cores/config.rb +13 -18
- data/lib/jekyll-spaceship/cores/processor.rb +13 -6
- data/lib/jekyll-spaceship/processors/element-processor.rb +152 -0
- data/lib/jekyll-spaceship/processors/emoji-processor.rb +14 -10
- data/lib/jekyll-spaceship/processors/mathjax-processor.rb +9 -0
- data/lib/jekyll-spaceship/processors/plantuml-processor.rb +19 -8
- data/lib/jekyll-spaceship/processors/table-processor.rb +9 -6
- data/lib/jekyll-spaceship/processors/video-processor.rb +33 -18
- data/lib/jekyll-spaceship/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38acd43c5d713728eb8beefc21a41ccff0404503138429c5fc695d5a92b0fbb5
|
4
|
+
data.tar.gz: aa0e6b588b3f778ef332ec83604ba26a3d238de34bfb458a7f85d1c3b006c0f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53ad3ff1458d8b5a1cde457ec7fa34672680f334fddb1613ebec356a461f0c7217faea14e361f0e022b3dceb7789d0ff7fa5d069d95c190343008d9485630f76
|
7
|
+
data.tar.gz: 97606894a42e2fa2fc34e66fb9b3cbb6013587696ed70bf8153a9b5bd2cf81f6444ee9337d13d672f3c3afe3c504039fd754b51deee9324c3df6287bee7c6b53
|
data/README.md
CHANGED
@@ -64,8 +64,8 @@
|
|
64
64
|
|
65
65
|
<div align="center">
|
66
66
|
<h4>
|
67
|
-
<a href="#requirements">Requirements</a> |
|
68
67
|
<a href="#installation">Install</a> |
|
68
|
+
<a href="#configuration">Config</a> |
|
69
69
|
<a href="#usage">Usage</a> |
|
70
70
|
<a href="#credits">Credits</a> |
|
71
71
|
<a href="#license">License</a>
|
@@ -80,10 +80,10 @@
|
|
80
80
|
<br>
|
81
81
|
|
82
82
|
|
83
|
-
|
83
|
+
Spaceship is a minimalistic, powerful and extremely customizable [Jekyll](https://jekyllrb.com/) plugin. It combines everything you may need for convenient work, without unnecessary complications, like a real spaceship.
|
84
84
|
|
85
85
|
<p align="center">
|
86
|
-
<img alt="Jekyll Spaceship Demo" src="https://user-images.githubusercontent.com/9413601/82250463-15451780-997e-11ea-8809-f411586d9508.gif"
|
86
|
+
<img alt="Jekyll Spaceship Demo" src="https://user-images.githubusercontent.com/9413601/82250463-15451780-997e-11ea-8809-f411586d9508.gif" />
|
87
87
|
</p>
|
88
88
|
|
89
89
|
**💡 Tip:** I hope you enjoy using this plugin. If you like this project, **a little star** for it is your way make a clear statement: **My work is valued**. I would appreciate your support! _Thank you!_
|
@@ -93,6 +93,7 @@ A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, emoji
|
|
93
93
|
|
94
94
|
- [Requirements](#requirements)
|
95
95
|
- [Installation](#installation)
|
96
|
+
- [Configuration](#configuration)
|
96
97
|
- [Usage](#usage)
|
97
98
|
- [1. Table Usage](#1-table-usage)
|
98
99
|
- [1.1 Rowspan and Colspan](#rowspan-and-colspan)
|
@@ -108,10 +109,13 @@ A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, emoji
|
|
108
109
|
- [4.1 Youtube Usage](#youtube-usage)
|
109
110
|
- [4.2 Vimeo Usage](#vimeo-usage)
|
110
111
|
- [4.3 DailyMotion Usage](#dailymotion-usage)
|
112
|
+
- [4.4 General Video Usage](#general-video-usage)
|
111
113
|
- [5. Hybrid HTML with Markdown](#5-hybrid-html-with-markdown)
|
112
114
|
- [6. Markdown Polyfill](#6-markdown-polyfill)
|
113
115
|
- [6.1 Escape Ordered List](#escape-ordered-list)
|
114
116
|
- [7. Emoji Usage](#7-emoji-usage)
|
117
|
+
- [7.1 Emoji Customizing](#71-emoji-customizing)
|
118
|
+
- [8. Modifying Element Usage](#8-modifying-element-usage)
|
115
119
|
- [Credits](#credits)
|
116
120
|
- [Contributing](#contributing)
|
117
121
|
- [License](#license)
|
@@ -137,6 +141,34 @@ plugins:
|
|
137
141
|
|
138
142
|
**💡 Tip:** Note that GitHub Pages runs in `safe` mode and only allows [a set of whitelisted plugins](https://pages.github.com/versions/). To use the gem in GitHub Pages, you need to build locally or use CI (e.g. [travis](https://travis-ci.org/), [github workflow](https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow)) and deploy to your `gh-pages` branch. [Click here for more information.](https://jekyllrb.com/docs/continuous-integration/github-actions/) (e.g. [https://github.com/jeffreytse/jekyll-jeffreytse-blog](https://github.com/jeffreytse/jekyll-jeffreytse-blog))
|
139
143
|
|
144
|
+
## Configuration
|
145
|
+
|
146
|
+
This plugin runs with the following configuration options by default. Alternative settings for these options can be explicitly specified in the configuration file `_config.yml`.
|
147
|
+
|
148
|
+
```yml
|
149
|
+
# Where things are
|
150
|
+
jekyll-spaceship:
|
151
|
+
processors:
|
152
|
+
- table-processor
|
153
|
+
- mathjax-processor
|
154
|
+
- plantuml-processor
|
155
|
+
- polyfill-processor
|
156
|
+
- video-processor
|
157
|
+
- emoji-processor
|
158
|
+
- element-processor
|
159
|
+
mathjax-processor:
|
160
|
+
src: //cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
|
161
|
+
config:
|
162
|
+
tex2jax:
|
163
|
+
inlineMath:
|
164
|
+
- ['$','$']
|
165
|
+
- ['\(','\)']
|
166
|
+
plantuml-processor:
|
167
|
+
src: http://www.plantuml.com/plantuml/png/
|
168
|
+
emoji-processor:
|
169
|
+
src: https://github.githubassets.com/images/icons/emoji/
|
170
|
+
```
|
171
|
+
|
140
172
|
## Usage
|
141
173
|
|
142
174
|
### 1. Table Usage
|
@@ -548,6 +580,7 @@ While its not possible to embed a video in markdown, the best and easiest way is
|
|
548
580
|
- Youtube
|
549
581
|
- Vimeo
|
550
582
|
- DailyMotion
|
583
|
+
- General Video ( mp4 | avi | webm | ogg | ogv | 3gp | flv | mov ... )
|
551
584
|
|
552
585
|
There are two ways to embed a video in your Jekyll blog page:
|
553
586
|
|
@@ -606,6 +639,21 @@ the link as below:
|
|
606
639
|

|
607
640
|
```
|
608
641
|
|
642
|
+
#### General Video Usage
|
643
|
+
|
644
|
+
```markdown
|
645
|
+

|
646
|
+
```
|
647
|
+
|
648
|
+
```markdown
|
649
|
+

|
650
|
+
```
|
651
|
+
|
652
|
+
```markdown
|
653
|
+

|
654
|
+
```
|
655
|
+
|
656
|
+
|
609
657
|
### 5. Hybrid HTML with Markdown
|
610
658
|
|
611
659
|
As markdown is not only a lightweight markup language with plain-text-formatting syntax, but also an easy-to-read and easy-to-write plain text format, so writing a hybrid HTML with markdown is an awesome choice.
|
@@ -697,12 +745,114 @@ I give this plugin two :+1:!
|
|
697
745
|
|
698
746
|
I give this plugin two :+1:!
|
699
747
|
|
748
|
+
#### 7.1 Emoji Customizing
|
749
|
+
|
750
|
+
If you'd like to serve emoji images locally, or use a custom emoji source, you can specify so in your `_config.yml` file:
|
751
|
+
|
752
|
+
```yml
|
753
|
+
jekyll-spaceship:
|
754
|
+
emoji-processor:
|
755
|
+
src: "/assets/images/emoji"
|
756
|
+
```
|
757
|
+
|
758
|
+
See the [Gemoji](https://github.com/github/gemoji) documentation for generating image files.
|
759
|
+
|
760
|
+
### 8. Modifying Element Usage
|
761
|
+
|
762
|
+
It allows us to modify elements via `CSS3 selectors`. Through it you can easily
|
763
|
+
modify the attributes of an element tag, replace the children nodes and so on,
|
764
|
+
it's very flexible, but here is example usage for modifying a document:
|
765
|
+
|
766
|
+
```yml
|
767
|
+
# Here is a comprehensive example
|
768
|
+
jekyll-spaceship:
|
769
|
+
element-processor:
|
770
|
+
css:
|
771
|
+
- a: '<h1>Test</h1>' # Replace all `a` tags (String Style)
|
772
|
+
- ['a.link1', 'a.link2']: # Replace all `a.link1`, `a.link2` tags (Hash Style)
|
773
|
+
name: img # Replace element tag name
|
774
|
+
props: # Replace element properties
|
775
|
+
title: Good image # Add a title attribute
|
776
|
+
src: ['(^.*$)', '\0?a=123'] # Add query string to src attribute by regex pattern
|
777
|
+
style: # Add style attribute (Hash Style)
|
778
|
+
color: red
|
779
|
+
font-size: '1.2em'
|
780
|
+
children: # Add children to the element
|
781
|
+
- # First empty for adding after the last child node
|
782
|
+
- "<span>Google</span>" # First child node (String Style)
|
783
|
+
- # Middle empty for wrapping the children nodes
|
784
|
+
- name: span # Second child node (Hash Style)
|
785
|
+
props:
|
786
|
+
prop1: "1" # Custom property1
|
787
|
+
prop2: "2" # Custom property2
|
788
|
+
prop3: "3" # Custom property3
|
789
|
+
children: # Add nested chidren nodes
|
790
|
+
- "<span>Jekyll</span>" # First child node (String Style)
|
791
|
+
- name: span # Second child node (Hash Style)
|
792
|
+
props: # Add attributes to child node (Hash Style)
|
793
|
+
prop1: "a"
|
794
|
+
prop2: "b"
|
795
|
+
prop3: "c"
|
796
|
+
children: "<b>Yap!</b>" # Add children nodes (String Style)
|
797
|
+
- # Last empty for adding before the first child node
|
798
|
+
- a.link: '<a href="//t.com">Link</a>' # Replace all `a.link` tags (String Style)
|
799
|
+
- 'h1#title': # Replace `h1#title` tags (Hash Style)
|
800
|
+
children: I'm a title! # Replace inner html to new text
|
801
|
+
```
|
802
|
+
|
803
|
+
#### Example 1
|
804
|
+
|
805
|
+
Automatically adds a `target="_blank" rel="noopener noreferrer"` attribute to all external links in Jekyll's content.
|
806
|
+
|
807
|
+
```yml
|
808
|
+
jekyll-spaceship:
|
809
|
+
element-processor:
|
810
|
+
css:
|
811
|
+
- a: # Replce all `a` tags
|
812
|
+
props:
|
813
|
+
class: ['(^.*$)', '\0 ext-link'] # Add `ext-link` to class by regex pattern
|
814
|
+
target: _blank # Replace `target` value to `_blank`
|
815
|
+
rel: noopener noreferrer # Replace `rel` value to `noopener noreferrer`
|
816
|
+
```
|
817
|
+
|
818
|
+
#### Example 2
|
819
|
+
|
820
|
+
Automatically adds `loading="lazy"` to `img` and `iframe` tags to natively load lazily.
|
821
|
+
[Browser support](https://caniuse.com/#feat=loading-lazy-attr) is growing. If a browser does not support the `loading` attribute, it will load the resource just like it would normally.
|
822
|
+
|
823
|
+
```yml
|
824
|
+
jekyll-spaceship:
|
825
|
+
element-processor:
|
826
|
+
css:
|
827
|
+
- a: # Replce all `a` tags
|
828
|
+
props: #
|
829
|
+
loading: lazy # Replace `lading` value to `lazy`
|
830
|
+
```
|
831
|
+
|
832
|
+
In case you want to prevent loading some images/iframes lazily, add
|
833
|
+
`loading="eager"` to their tags. This might be useful to prevent flickering of
|
834
|
+
images during navigation (e.g. the site's logo).
|
835
|
+
|
836
|
+
See the following examples to prevent lazy loading.
|
837
|
+
|
838
|
+
```yml
|
839
|
+
jekyll-spaceship:
|
840
|
+
element-processor:
|
841
|
+
css:
|
842
|
+
- a: # Replce all `a` tags
|
843
|
+
props: #
|
844
|
+
loading: eager # Replace `loading` value to `eager`
|
845
|
+
```
|
846
|
+
|
847
|
+
|
700
848
|
## Credits
|
701
849
|
|
702
850
|
- [Jekyll](https://github.com/jekyll/jekyll) - A blog-aware static site generator in Ruby.
|
703
851
|
- [MultiMarkdown](https://fletcher.github.io/MultiMarkdown-6) - Lightweight markup processor to produce HTML, LaTeX, and more.
|
704
852
|
- [markdown-it-multimd-table](https://github.com/RedBug312/markdown-it-multimd-table) - Multimarkdown table syntax plugin for markdown-it markdown parser.
|
705
853
|
- [jmoji](https://github.com/jekyll/jemoji) - GitHub-flavored emoji plugin for Jekyll.
|
854
|
+
- [jekyll-target-blank](https://github.com/keithmifsud/jekyll-target-blank) - Automatically opens external links in a new browser for Jekyll Pages, Posts and Docs.
|
855
|
+
- [jekyll-loading-lazy](https://github.com/gildesmarais/jekyll-loading-lazy) - Automatically adds loading="lazy" to img and iframe tags to natively load lazily.
|
706
856
|
|
707
857
|
## Contributing
|
708
858
|
|
data/jekyll-spaceship.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.version = Jekyll::Spaceship::VERSION
|
10
10
|
spec.authors = ["jeffreytse"]
|
11
11
|
spec.email = ["jeffreytse.mail@gmail.com"]
|
12
|
-
spec.summary = "A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, emoji, youtube, vimeo, dailymotion, etc."
|
12
|
+
spec.summary = "A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, emoji, video, youtube, vimeo, dailymotion, etc."
|
13
13
|
spec.homepage = "https://github.com/jeffreytse/jekyll-spaceship"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -12,20 +12,9 @@ module Jekyll::Spaceship
|
|
12
12
|
'plantuml-processor',
|
13
13
|
'polyfill-processor',
|
14
14
|
'video-processor',
|
15
|
-
'emoji-processor'
|
16
|
-
|
17
|
-
|
18
|
-
'src' => '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML',
|
19
|
-
'config' => {
|
20
|
-
'tex2jax' => { 'inlineMath' => [['$','$'], ['\\(','\\)']] }
|
21
|
-
}
|
22
|
-
},
|
23
|
-
'plantuml-processor' => {
|
24
|
-
'src' => 'http://www.plantuml.com/plantuml/png/'
|
25
|
-
},
|
26
|
-
'emoji-processor' => {
|
27
|
-
'src' => 'https://github.githubassets.com/images/icons/emoji/'
|
28
|
-
}
|
15
|
+
'emoji-processor',
|
16
|
+
'element-processor'
|
17
|
+
]
|
29
18
|
}
|
30
19
|
|
31
20
|
@@store = {}
|
@@ -43,14 +32,16 @@ module Jekyll::Spaceship
|
|
43
32
|
first.merge(second.to_h, &merger)
|
44
33
|
end
|
45
34
|
|
46
|
-
def self.store(section)
|
47
|
-
@@store[section]
|
35
|
+
def self.store(section, default)
|
36
|
+
return if @@store[section].nil?
|
37
|
+
return @@store[section] if default.nil?
|
38
|
+
@@store[section] = deep_merge(default, @@store[section])
|
48
39
|
end
|
49
40
|
|
50
|
-
def self.load(
|
41
|
+
def self.load(config = self.site_config)
|
51
42
|
config = deep_merge(
|
52
43
|
{ CONFIG_NAME => DEFAULT_CONFIG },
|
53
|
-
|
44
|
+
config
|
54
45
|
)[CONFIG_NAME]
|
55
46
|
@@store = config
|
56
47
|
self.use_processors(config)
|
@@ -61,5 +52,9 @@ module Jekyll::Spaceship
|
|
61
52
|
Register.use processor
|
62
53
|
end
|
63
54
|
end
|
55
|
+
|
56
|
+
def self.site_config
|
57
|
+
Jekyll.sites.first.config
|
58
|
+
end
|
64
59
|
end
|
65
60
|
end
|
@@ -41,7 +41,8 @@ module Jekyll::Spaceship
|
|
41
41
|
self.initialize_register
|
42
42
|
self.initialize_exclusions
|
43
43
|
@logger = Logger.new(self.name)
|
44
|
-
@config = Config.store(self.filename)
|
44
|
+
@config = Config.store(self.filename, self.class.config)
|
45
|
+
@handled_files = {}
|
45
46
|
end
|
46
47
|
|
47
48
|
def initialize_priority
|
@@ -56,7 +57,7 @@ module Jekyll::Spaceship
|
|
56
57
|
def initialize_register
|
57
58
|
if @@_registers.size.zero?
|
58
59
|
self.class.register :pages, :pre_render, :post_render
|
59
|
-
self.class.register :
|
60
|
+
self.class.register :documents, :pre_render, :post_render
|
60
61
|
end
|
61
62
|
@registers = Array.new @@_registers
|
62
63
|
@@_registers.clear
|
@@ -82,6 +83,9 @@ module Jekyll::Spaceship
|
|
82
83
|
@@_exclusions = types
|
83
84
|
end
|
84
85
|
|
86
|
+
def self.config
|
87
|
+
end
|
88
|
+
|
85
89
|
def process?
|
86
90
|
Type.html?(output_ext) or Type.markdown?(ext)
|
87
91
|
end
|
@@ -140,7 +144,10 @@ module Jekyll::Spaceship
|
|
140
144
|
end
|
141
145
|
|
142
146
|
def on_handled
|
143
|
-
|
147
|
+
source = page.site.source
|
148
|
+
file = page.path.sub(/^#{source}\//, '')
|
149
|
+
return if @handled_files.has_key? file
|
150
|
+
@handled_files[file] = true
|
144
151
|
logger.log file
|
145
152
|
end
|
146
153
|
|
@@ -149,13 +156,13 @@ module Jekyll::Spaceship
|
|
149
156
|
@exclusions.each do |type|
|
150
157
|
regex = nil
|
151
158
|
if type == :code
|
152
|
-
regex = /(
|
159
|
+
regex = /((`+)\s*(\w*)((?:.|\n)*?)\2)/
|
153
160
|
end
|
154
161
|
next if regex.nil?
|
155
162
|
content.scan(regex) do |match_data|
|
156
163
|
match = match_data[0]
|
157
164
|
id = @exclusion_store.size
|
158
|
-
content = content.
|
165
|
+
content = content.sub(match, "[JEKYLL@#{object_id}@#{id}]")
|
159
166
|
@exclusion_store.push match
|
160
167
|
end
|
161
168
|
end
|
@@ -166,7 +173,7 @@ module Jekyll::Spaceship
|
|
166
173
|
while @exclusion_store.size > 0
|
167
174
|
match = @exclusion_store.pop
|
168
175
|
id = @exclusion_store.size
|
169
|
-
content = content.
|
176
|
+
content = content.sub("[JEKYLL@#{object_id}@#{id}]", match)
|
170
177
|
end
|
171
178
|
@exclusion_store = []
|
172
179
|
content
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
module Jekyll::Spaceship
|
6
|
+
class ElementProcessor < Processor
|
7
|
+
priority :lowest
|
8
|
+
|
9
|
+
def self.config
|
10
|
+
{ 'css' => [] }
|
11
|
+
end
|
12
|
+
|
13
|
+
def on_handle_html(content)
|
14
|
+
return content if config['css'].size.zero?
|
15
|
+
|
16
|
+
# use nokogiri to parse html content
|
17
|
+
doc = Nokogiri::HTML(content)
|
18
|
+
|
19
|
+
# handle each css pattern
|
20
|
+
config['css'].each do |data|
|
21
|
+
data.each do |key, val|
|
22
|
+
key = [key] if key.kind_of? String
|
23
|
+
key.each do |pattern|
|
24
|
+
nodes = doc.css(pattern)
|
25
|
+
nodes.each do |element|
|
26
|
+
handle_css_pattern({
|
27
|
+
:doc => doc,
|
28
|
+
:element => element,
|
29
|
+
:data => val
|
30
|
+
})
|
31
|
+
end
|
32
|
+
self.handled = true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
doc.to_html
|
38
|
+
end
|
39
|
+
|
40
|
+
def handle_css_pattern(data)
|
41
|
+
doc = data[:doc]
|
42
|
+
element = data[:element]
|
43
|
+
data = data[:data]
|
44
|
+
|
45
|
+
if data.kind_of? String
|
46
|
+
element.replace Nokogiri::HTML.fragment(data)
|
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({
|
71
|
+
:doc => doc,
|
72
|
+
:data => data['children']
|
73
|
+
})
|
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
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def create_children(data)
|
107
|
+
doc = data[:doc]
|
108
|
+
data = data[:data]
|
109
|
+
root = Nokogiri::HTML.fragment("")
|
110
|
+
|
111
|
+
data = [data] unless data.kind_of? Array
|
112
|
+
data.each do |child_data|
|
113
|
+
node = self.create_element({
|
114
|
+
:doc => doc,
|
115
|
+
:data => child_data
|
116
|
+
})
|
117
|
+
next if node.nil?
|
118
|
+
unless child_data['children'].nil?
|
119
|
+
node.children = self.create_children({
|
120
|
+
:doc => doc,
|
121
|
+
:data => child_data['children']
|
122
|
+
})
|
123
|
+
end
|
124
|
+
root.add_child node
|
125
|
+
end
|
126
|
+
root.children
|
127
|
+
end
|
128
|
+
|
129
|
+
def create_element(data)
|
130
|
+
doc = data[:doc]
|
131
|
+
data = data[:data]
|
132
|
+
|
133
|
+
return if data.nil?
|
134
|
+
return Nokogiri::HTML.fragment(data) if data.kind_of? String
|
135
|
+
return if data['name'].nil?
|
136
|
+
|
137
|
+
# create node
|
138
|
+
node = doc.create_element(data['name'])
|
139
|
+
|
140
|
+
# set props
|
141
|
+
data['props']&.each do |prop, val|
|
142
|
+
if val.kind_of? Hash
|
143
|
+
result = []
|
144
|
+
val.each { |k, v| result.push "#{k}: #{v}" }
|
145
|
+
val = result.join(";")
|
146
|
+
end
|
147
|
+
node.set_attribute(prop, val)
|
148
|
+
end
|
149
|
+
node
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -6,6 +6,10 @@ require 'gemoji'
|
|
6
6
|
|
7
7
|
module Jekyll::Spaceship
|
8
8
|
class EmojiProcessor < Processor
|
9
|
+
def self.config
|
10
|
+
{ 'src' => 'https://github.githubassets.com/images/icons/emoji/' }
|
11
|
+
end
|
12
|
+
|
9
13
|
def on_handle_html(content)
|
10
14
|
# handle emoji markup
|
11
15
|
content.scan(/:([\w\d+-]+):/) do |match|
|
@@ -18,16 +22,16 @@ module Jekyll::Spaceship
|
|
18
22
|
|
19
23
|
content = content.gsub(
|
20
24
|
/(?<!\=")\s*:#{emoji_name}:\s*(?!"\s)/,
|
21
|
-
"<img class=\"emoji\"
|
22
|
-
title=\":#{emoji.name}:\"
|
23
|
-
alt=\":#{emoji.name}:\"
|
24
|
-
raw=\"#{emoji.raw}\"
|
25
|
-
src=\"#{config['src']}#{emoji.image_filename}\"
|
26
|
-
style=\"vertical-align: middle;
|
27
|
-
max-width: 1em; visibility: hidden;\"
|
28
|
-
onload=\"this.style.visibility='visible'\"
|
29
|
-
onerror=\"this.replaceWith(this.getAttribute('raw'))\">
|
30
|
-
</img>"
|
25
|
+
"<img class=\"emoji\""\
|
26
|
+
" title=\":#{emoji.name}:\""\
|
27
|
+
" alt=\":#{emoji.name}:\""\
|
28
|
+
" raw=\"#{emoji.raw}\""\
|
29
|
+
" src=\"#{config['src']}#{emoji.image_filename}\""\
|
30
|
+
" style=\"vertical-align: middle;"\
|
31
|
+
" max-width: 1em; visibility: hidden;\""\
|
32
|
+
" onload=\"this.style.visibility='visible'\""\
|
33
|
+
" onerror=\"this.replaceWith(this.getAttribute('raw'))\">"\
|
34
|
+
"</img>"
|
31
35
|
)
|
32
36
|
end
|
33
37
|
content
|
@@ -4,6 +4,15 @@ require "nokogiri"
|
|
4
4
|
|
5
5
|
module Jekyll::Spaceship
|
6
6
|
class MathjaxProcessor < Processor
|
7
|
+
def self.config
|
8
|
+
{
|
9
|
+
'src' => '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML',
|
10
|
+
'config' => {
|
11
|
+
'tex2jax' => { 'inlineMath' => [['$','$'], ['\\(','\\)']] }
|
12
|
+
}
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
7
16
|
def process?
|
8
17
|
return true if Type.html?(output_ext)
|
9
18
|
end
|
@@ -7,17 +7,30 @@ module Jekyll::Spaceship
|
|
7
7
|
class PlantumlProcessor < Processor
|
8
8
|
exclude :none
|
9
9
|
|
10
|
+
PLANTUML_PATTERNS = [
|
11
|
+
/(\\?(@startuml)((?:.|\n)*?)@enduml)/,
|
12
|
+
/((`{3,})\s*plantuml((?:.|\n)*?)\2)/
|
13
|
+
]
|
14
|
+
|
15
|
+
def self.config
|
16
|
+
{ 'src' => 'http://www.plantuml.com/plantuml/png/' }
|
17
|
+
end
|
18
|
+
|
10
19
|
def on_handle_markdown(content)
|
11
20
|
# match default plantuml block and code block
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
)
|
21
|
+
PLANTUML_PATTERNS.each do |pattern|
|
22
|
+
content = handle_plantuml_block(pattern, content)
|
23
|
+
end
|
16
24
|
|
25
|
+
# handle escape default plantuml block
|
26
|
+
content.gsub(/\\(@startuml|@enduml)/, '\1')
|
27
|
+
end
|
28
|
+
|
29
|
+
def handle_plantuml_block(pattern, content)
|
17
30
|
content.scan pattern do |match|
|
18
31
|
match = match.select { |m| not m.nil? }
|
19
32
|
block = match[0]
|
20
|
-
code = match[
|
33
|
+
code = match[2]
|
21
34
|
|
22
35
|
# skip escape default plantuml block
|
23
36
|
if block.match(/(^\\@startuml|\\@enduml$)/)
|
@@ -31,9 +44,7 @@ module Jekyll::Spaceship
|
|
31
44
|
handle_plantuml(code)
|
32
45
|
)
|
33
46
|
end
|
34
|
-
|
35
|
-
# handle escape default plantuml block
|
36
|
-
content.gsub(/\\(@startuml|@enduml)/, '\1')
|
47
|
+
content
|
37
48
|
end
|
38
49
|
|
39
50
|
def handle_plantuml(code)
|
@@ -157,7 +157,7 @@ module Jekyll::Spaceship
|
|
157
157
|
if scope.table.multi_row_cells != cells and scope.table.multi_row_start
|
158
158
|
for i in 0...scope.table.multi_row_cells.count do
|
159
159
|
multi_row_cell = scope.table.multi_row_cells[i]
|
160
|
-
multi_row_cell.
|
160
|
+
multi_row_cell.inner_html += "<br>#{cells[i].inner_html}"
|
161
161
|
end
|
162
162
|
row.remove
|
163
163
|
end
|
@@ -182,7 +182,7 @@ module Jekyll::Spaceship
|
|
182
182
|
span_cell = scope.table.span_row_cells[scope.row.col_index]
|
183
183
|
if span_cell and cell.content.match(/^\s*\^{2}/)
|
184
184
|
cell.content = cell.content.gsub(/^\s*\^{2}/, '')
|
185
|
-
span_cell.
|
185
|
+
span_cell.inner_html += "<br>#{cell.inner_html}"
|
186
186
|
rowspan = span_cell.get_attribute('rowspan') || 1
|
187
187
|
rowspan = rowspan.to_i + 1
|
188
188
|
span_cell.set_attribute('rowspan', "#{rowspan}")
|
@@ -207,11 +207,12 @@ module Jekyll::Spaceship
|
|
207
207
|
align += 2
|
208
208
|
end
|
209
209
|
|
210
|
+
# handle text align
|
211
|
+
return if align == 0
|
212
|
+
|
210
213
|
# handle escape colon
|
211
214
|
cell.content = cell.content.gsub(/\\:/, ':')
|
212
215
|
|
213
|
-
# handle text align
|
214
|
-
return if align == 0
|
215
216
|
style = cell.get_attribute('style')
|
216
217
|
if align == 1
|
217
218
|
align = 'text-align: left'
|
@@ -234,8 +235,10 @@ module Jekyll::Spaceship
|
|
234
235
|
cell = data.cell
|
235
236
|
cvter = self.converter('markdown')
|
236
237
|
return if cvter.nil?
|
237
|
-
content = cell.
|
238
|
-
|
238
|
+
content = cell.inner_html
|
239
|
+
.gsub(/(?<!\\)\|/, '\\|')
|
240
|
+
.gsub(/^\s+|\s+$/, '')
|
241
|
+
content = cvter.convert(content)
|
239
242
|
cell.inner_html = Nokogiri::HTML.fragment(content)
|
240
243
|
end
|
241
244
|
end
|
@@ -5,11 +5,23 @@ require 'uri'
|
|
5
5
|
module Jekyll::Spaceship
|
6
6
|
class VideoProcessor < Processor
|
7
7
|
def on_handle_markdown(content)
|
8
|
+
content = handle_normal_video(content)
|
8
9
|
content = handle_youtube(content)
|
9
10
|
content = handle_vimeo(content)
|
10
11
|
content = handle_dailymotion(content)
|
11
12
|
end
|
12
13
|
|
14
|
+
# Examples:
|
15
|
+
# 
|
16
|
+
# 
|
17
|
+
# 
|
18
|
+
def handle_normal_video(content)
|
19
|
+
handle_video(content, {
|
20
|
+
host: '(https?:)?\\/\\/.*\\/',
|
21
|
+
id: '(.+?\\.(avi|mp4|webm|ogg|ogv|flv|mkv|mov|wmv|3gp|rmvb|asf))',
|
22
|
+
})
|
23
|
+
end
|
24
|
+
|
13
25
|
# Examples:
|
14
26
|
# 
|
15
27
|
# 
|
@@ -29,9 +41,7 @@ module Jekyll::Spaceship
|
|
29
41
|
handle_video(content, {
|
30
42
|
host: '(https?:)?\\/\\/vimeo\\.com\\/',
|
31
43
|
id: '([0-9]+)',
|
32
|
-
iframe_url: "https://player.vimeo.com/video/"
|
33
|
-
width: 600,
|
34
|
-
height: 350
|
44
|
+
iframe_url: "https://player.vimeo.com/video/"
|
35
45
|
})
|
36
46
|
end
|
37
47
|
|
@@ -77,25 +87,30 @@ module Jekyll::Spaceship
|
|
77
87
|
next true if v == id or v == ''
|
78
88
|
end
|
79
89
|
|
80
|
-
|
81
|
-
|
82
|
-
|
90
|
+
css_id = qs['id'] || "video-#{id}"
|
91
|
+
css_class = qs['class'] || 'video'
|
92
|
+
width = qs['width'] || data[:width] || "100%"
|
93
|
+
height = qs['height'] || data[:height] || 350
|
94
|
+
frameborder = qs['frameborder'] || 0
|
95
|
+
style = qs['style'] || 'max-width: 600px'
|
96
|
+
allow = qs['allow'] || "encrypted-media; picture-in-picture"
|
83
97
|
|
84
|
-
url = URI("#{iframe_url}#{id}").tap do |v|
|
98
|
+
url = URI(iframe_url ? "#{iframe_url}#{id}" : url).tap do |v|
|
85
99
|
v.query = URI.encode_www_form(qs) if qs.size > 0
|
86
100
|
end
|
87
101
|
|
88
|
-
html = "<iframe
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
102
|
+
html = "<iframe"\
|
103
|
+
" id=\"#{css_id}\""\
|
104
|
+
" class=\"#{css_class}\""\
|
105
|
+
" src=\"#{url}\""\
|
106
|
+
" title=\"#{title}\""\
|
107
|
+
" width=\"#{width}\""\
|
108
|
+
" height=\"#{height}\""\
|
109
|
+
" style=\"#{style}\""\
|
110
|
+
" allow=\"#{allow}\""\
|
111
|
+
" frameborder=\"#{frameborder}\""\
|
112
|
+
" allowfullscreen>" \
|
113
|
+
"</iframe>"
|
99
114
|
|
100
115
|
content = content.gsub(match_data[0], html)
|
101
116
|
self.handled = true
|
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.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jeffreytse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- lib/jekyll-spaceship/cores/processor.rb
|
138
138
|
- lib/jekyll-spaceship/cores/register.rb
|
139
139
|
- lib/jekyll-spaceship/cores/type.rb
|
140
|
+
- lib/jekyll-spaceship/processors/element-processor.rb
|
140
141
|
- lib/jekyll-spaceship/processors/emoji-processor.rb
|
141
142
|
- lib/jekyll-spaceship/processors/mathjax-processor.rb
|
142
143
|
- lib/jekyll-spaceship/processors/plantuml-processor.rb
|
@@ -172,5 +173,5 @@ rubygems_version: 2.7.7
|
|
172
173
|
signing_key:
|
173
174
|
specification_version: 4
|
174
175
|
summary: A Jekyll plugin to provide powerful supports for table, mathjax, plantuml,
|
175
|
-
emoji, youtube, vimeo, dailymotion, etc.
|
176
|
+
emoji, video, youtube, vimeo, dailymotion, etc.
|
176
177
|
test_files: []
|