jekyll-spaceship 0.7.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +112 -41
- data/jekyll-spaceship.gemspec +1 -1
- data/lib/jekyll-spaceship.rb +1 -1
- data/lib/jekyll-spaceship/cores/config.rb +7 -3
- data/lib/jekyll-spaceship/cores/processor.rb +3 -1
- data/lib/jekyll-spaceship/processors/element-processor.rb +71 -53
- data/lib/jekyll-spaceship/processors/emoji-processor.rb +7 -2
- data/lib/jekyll-spaceship/processors/mermaid-processor.rb +116 -0
- data/lib/jekyll-spaceship/processors/plantuml-processor.rb +55 -24
- data/lib/jekyll-spaceship/processors/table-processor.rb +13 -9
- data/lib/jekyll-spaceship/processors/video-processor.rb +25 -7
- 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: c2a6f219ec49d2767f11891946203051ed55b82567d0021c929eb1831769e246
|
4
|
+
data.tar.gz: 80bdf4869aaf201752f791031b6730b0d3e86681cdb246f4855db960ec913a60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7ff25fd47603c5f3471db4d33cad716956ee41918fa5408fae35176025658122ee4cc567db6a68675d4c1e677d9f7b50a0e32ce12fb0eae1a3e8525503be8f0
|
7
|
+
data.tar.gz: ca6a2e4071c8eac5f8759778bb2c0e228a3b94369c16815fb150e8041b685a11e60f18dcd7f05afae3e9fbcf8075b5bfb61046248ff440b5dbefb80cedcef02e
|
data/README.md
CHANGED
@@ -105,17 +105,18 @@ Spaceship is a minimalistic, powerful and extremely customizable [Jekyll](https:
|
|
105
105
|
- [2.1 Performance Optimization](#21-performance-optimization)
|
106
106
|
- [2.2 How to use?](#22-how-to-use)
|
107
107
|
- [3. PlantUML Usage](#3-plantuml-usage)
|
108
|
-
- [4.
|
109
|
-
|
110
|
-
- [
|
111
|
-
- [
|
112
|
-
- [
|
113
|
-
|
114
|
-
- [6. Markdown
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
108
|
+
- [4. Mermaid Usage](#4-mermaid-usage)
|
109
|
+
- [5. Video Usage](#5-video-usage)
|
110
|
+
- [5.1 Youtube Usage](#youtube-usage)
|
111
|
+
- [5.2 Vimeo Usage](#vimeo-usage)
|
112
|
+
- [5.3 DailyMotion Usage](#dailymotion-usage)
|
113
|
+
- [5.4 General Video Usage](#general-video-usage)
|
114
|
+
- [6. Hybrid HTML with Markdown](#6-hybrid-html-with-markdown)
|
115
|
+
- [7. Markdown Polyfill](#7-markdown-polyfill)
|
116
|
+
- [7.1 Escape Ordered List](#71-escape-ordered-list)
|
117
|
+
- [8. Emoji Usage](#8-emoji-usage)
|
118
|
+
- [8.1 Emoji Customizing](#81-emoji-customizing)
|
119
|
+
- [9. Modifying Element Usage](#9-modifying-element-usage)
|
119
120
|
- [Credits](#credits)
|
120
121
|
- [Contributing](#contributing)
|
121
122
|
- [License](#license)
|
@@ -139,7 +140,12 @@ plugins:
|
|
139
140
|
- jekyll-spaceship
|
140
141
|
```
|
141
142
|
|
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.
|
143
|
+
**💡 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.
|
144
|
+
|
145
|
+
### Additions
|
146
|
+
|
147
|
+
* Here is a GitHub Action named [jekyll-deploy-action](https://github.com/jeffreytse/jekyll-deploy-action) for Jekyll site deployment conveniently. 👍
|
148
|
+
* Here is a [Jekyll site](https://github.com/jeffreytse/jekyll-jeffreytse-blog) using Travis to build and deploy to GitHub Pages for your references.
|
143
149
|
|
144
150
|
## Configuration
|
145
151
|
|
@@ -148,10 +154,12 @@ This plugin runs with the following configuration options by default. Alternativ
|
|
148
154
|
```yml
|
149
155
|
# Where things are
|
150
156
|
jekyll-spaceship:
|
157
|
+
# default enabled processors
|
151
158
|
processors:
|
152
159
|
- table-processor
|
153
160
|
- mathjax-processor
|
154
161
|
- plantuml-processor
|
162
|
+
- mermaid-processor
|
155
163
|
- polyfill-processor
|
156
164
|
- video-processor
|
157
165
|
- emoji-processor
|
@@ -164,8 +172,35 @@ jekyll-spaceship:
|
|
164
172
|
- ['$','$']
|
165
173
|
- ['\(','\)']
|
166
174
|
plantuml-processor:
|
175
|
+
mode: default # mode value 'pre-fetch' for fetching image at building stage
|
176
|
+
css:
|
177
|
+
class: plantuml
|
178
|
+
syntax:
|
179
|
+
code: 'plantuml!'
|
180
|
+
custom: ['@startuml', '@enduml']
|
167
181
|
src: http://www.plantuml.com/plantuml/png/
|
182
|
+
mermaid-processor:
|
183
|
+
mode: default # mode value 'pre-fetch' for fetching image at building stage
|
184
|
+
css:
|
185
|
+
class: mermaid
|
186
|
+
syntax:
|
187
|
+
code: 'mermaid!'
|
188
|
+
custom: ['@startmermaid', '@endmermaid']
|
189
|
+
config:
|
190
|
+
theme: default
|
191
|
+
src: https://mermaid.ink/svg/
|
192
|
+
video-processor:
|
193
|
+
default:
|
194
|
+
id: 'video-{id}'
|
195
|
+
class: 'video'
|
196
|
+
width: '100%'
|
197
|
+
height: 350
|
198
|
+
border: 0
|
199
|
+
style: 'max-width: 600px'
|
200
|
+
allow: 'encrypted-media; picture-in-picture'
|
168
201
|
emoji-processor:
|
202
|
+
css:
|
203
|
+
class: emoji
|
169
204
|
src: https://github.githubassets.com/images/icons/emoji/
|
170
205
|
```
|
171
206
|
|
@@ -191,13 +226,13 @@ This feature is contributed by [pmccloghrylaing](https://github.com/pmccloghryla
|
|
191
226
|
```markdown
|
192
227
|
| Stage | Direct Products | ATP Yields |
|
193
228
|
| -----------------: | --------------: | ---------: |
|
194
|
-
| Glycolysis |
|
195
|
-
|
|
229
|
+
| Glycolysis | 2 ATP ||
|
230
|
+
| ^^ | 2 NADH | 3--5 ATP |
|
196
231
|
| Pyruvaye oxidation | 2 NADH | 5 ATP |
|
197
232
|
| Citric acid cycle | 2 ATP ||
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
233
|
+
| ^^ | 6 NADH | 15 ATP |
|
234
|
+
| ^^ | 2 FADH | 3 ATP |
|
235
|
+
| 30--32 ATP |||
|
201
236
|
```
|
202
237
|
|
203
238
|
Code above would be parsed as:
|
@@ -398,7 +433,7 @@ Table cell can be set alignment separately.
|
|
398
433
|
```markdown
|
399
434
|
| : Fruits \|\| Food : |||
|
400
435
|
| :--------- | :-------- | :-------- |
|
401
|
-
| Apple | :
|
436
|
+
| Apple | : Apple : | Apple \
|
402
437
|
| Banana | Banana | Banana \
|
403
438
|
| Orange | Orange | Orange |
|
404
439
|
| : Rowspan is 4 : || How's it? |
|
@@ -546,13 +581,13 @@ Code above would be parsed as:
|
|
546
581
|
- class diagram,
|
547
582
|
- activity diagram,
|
548
583
|
- component diagram,
|
549
|
-
- state diagram
|
584
|
+
- state diagram,
|
550
585
|
- object diagram
|
551
586
|
|
552
587
|
There are two ways to create a diagram in your Jekyll blog page:
|
553
588
|
|
554
|
-
````
|
555
|
-
```plantuml
|
589
|
+
````
|
590
|
+
```plantuml!
|
556
591
|
Bob -> Alice : hello world
|
557
592
|
```
|
558
593
|
````
|
@@ -569,7 +604,48 @@ Code above would be parsed as:
|
|
569
604
|
|
570
605
|
![PlantUML Diagram](https://user-images.githubusercontent.com/9413601/82813883-9180b300-9ec8-11ea-8778-f450e0056938.png)
|
571
606
|
|
572
|
-
### 4.
|
607
|
+
### 4. Mermaid Usage
|
608
|
+
|
609
|
+
[Mermaid](https://mermaid-js.github.io/) is a Javascript based diagramming and charting tool. It generates diagrams flowcharts and more, using markdown-inspired text for ease and speed.
|
610
|
+
|
611
|
+
It allows to quickly write:
|
612
|
+
|
613
|
+
- flow chart,
|
614
|
+
- pie chart,
|
615
|
+
- sequence diagram,
|
616
|
+
- class diagram,
|
617
|
+
- state diagram,
|
618
|
+
- entity relationship diagram,
|
619
|
+
- user journey,
|
620
|
+
- gantt
|
621
|
+
|
622
|
+
There are two ways to create a diagram in your Jekyll blog page:
|
623
|
+
|
624
|
+
````
|
625
|
+
```mermaid!
|
626
|
+
pie title Pets adopted by volunteers
|
627
|
+
"Dogs" : 386
|
628
|
+
"Cats" : 85
|
629
|
+
"Rats" : 35
|
630
|
+
```
|
631
|
+
````
|
632
|
+
|
633
|
+
or
|
634
|
+
|
635
|
+
```markdown
|
636
|
+
@startmermaid
|
637
|
+
pie title Pets adopted by volunteers
|
638
|
+
"Dogs" : 386
|
639
|
+
"Cats" : 85
|
640
|
+
"Rats" : 35
|
641
|
+
@endmermaid
|
642
|
+
```
|
643
|
+
|
644
|
+
Code above would be parsed as:
|
645
|
+
|
646
|
+
![Mermaid Diagram](https://user-images.githubusercontent.com/9413601/85282355-2e317300-b4be-11ea-9c30-8f9d61540d14.png)
|
647
|
+
|
648
|
+
### 5. Video Usage
|
573
649
|
|
574
650
|
How often did you find yourself googling "**How to embed a video in markdown?**"
|
575
651
|
|
@@ -603,9 +679,7 @@ the link as below:
|
|
603
679
|
|
604
680
|
```markdown
|
605
681
|
![](https://www.youtube.com/watch?v=Ptk_1Dc2iPY?width=800&height=500)
|
606
|
-
```
|
607
682
|
|
608
|
-
```markdown
|
609
683
|
![](https://www.dailymotion.com/video/x7tfyq3?width=100%&height=400&autoplay=1)
|
610
684
|
```
|
611
685
|
|
@@ -613,9 +687,7 @@ the link as below:
|
|
613
687
|
|
614
688
|
```markdown
|
615
689
|
![](https://www.youtube.com/watch?v=Ptk_1Dc2iPY)
|
616
|
-
```
|
617
690
|
|
618
|
-
```markdown
|
619
691
|
![](//www.youtube.com/watch?v=Ptk_1Dc2iPY?width=800&height=500)
|
620
692
|
```
|
621
693
|
|
@@ -623,9 +695,7 @@ the link as below:
|
|
623
695
|
|
624
696
|
```markdown
|
625
697
|
![](https://vimeo.com/263856289)
|
626
|
-
```
|
627
698
|
|
628
|
-
```markdown
|
629
699
|
![](https://vimeo.com/263856289?width=500&height=320)
|
630
700
|
```
|
631
701
|
|
@@ -633,9 +703,7 @@ the link as below:
|
|
633
703
|
|
634
704
|
```markdown
|
635
705
|
![](https://www.dailymotion.com/video/x7tfyq3)
|
636
|
-
```
|
637
706
|
|
638
|
-
```markdown
|
639
707
|
![](https://dai.ly/x7tgcev?width=100%&height=400)
|
640
708
|
```
|
641
709
|
|
@@ -643,18 +711,14 @@ the link as below:
|
|
643
711
|
|
644
712
|
```markdown
|
645
713
|
![](//www.html5rocks.com/en/tutorials/video/basics/devstories.webm)
|
646
|
-
```
|
647
714
|
|
648
|
-
```markdown
|
649
715
|
![](//techslides.com/demos/sample-videos/small.ogv?allow=autoplay)
|
650
|
-
```
|
651
716
|
|
652
|
-
```markdown
|
653
717
|
![](//techslides.com/demos/sample-videos/small.mp4?width=400)
|
654
718
|
```
|
655
719
|
|
656
720
|
|
657
|
-
###
|
721
|
+
### 6. Hybrid HTML with Markdown
|
658
722
|
|
659
723
|
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.
|
660
724
|
|
@@ -668,7 +732,7 @@ It's easy to write markdown inside HTML:
|
|
668
732
|
|
669
733
|
| : Fruits \|\| Food : |||
|
670
734
|
| :--------- | :-------- | :-------- |
|
671
|
-
| Apple | :
|
735
|
+
| Apple | : Apple : | Apple \
|
672
736
|
| Banana | Banana | Banana \
|
673
737
|
| Orange | Orange | Orange |
|
674
738
|
| : Rowspan is 4 : || How's it? |
|
@@ -688,7 +752,7 @@ Bob -> Alice : hello
|
|
688
752
|
</script>
|
689
753
|
```
|
690
754
|
|
691
|
-
###
|
755
|
+
### 7. Markdown Polyfill
|
692
756
|
|
693
757
|
It allows us to polyfill features for extending markdown syntax.
|
694
758
|
|
@@ -696,7 +760,7 @@ It allows us to polyfill features for extending markdown syntax.
|
|
696
760
|
|
697
761
|
- Escape ordered list
|
698
762
|
|
699
|
-
#### Escape Ordered List
|
763
|
+
#### 7.1 Escape Ordered List
|
700
764
|
|
701
765
|
A backslash at begin to escape the ordered list.
|
702
766
|
|
@@ -730,7 +794,7 @@ Escaped:
|
|
730
794
|
10. List item Cafe.
|
731
795
|
```
|
732
796
|
|
733
|
-
###
|
797
|
+
### 8. Emoji Usage
|
734
798
|
GitHub-flavored emoji images and names would allow emojifying content such as: it's raining :cat:s and :dog:s!
|
735
799
|
|
736
800
|
Noted that emoji images are served from the GitHub.com CDN, with a base URL of [https://github.githubassets.com](https://github.githubassets.com), which results in emoji image URLs like [https://github.githubassets.com/images/icons/emoji/unicode/1f604.png](https://github.githubassets.com/images/icons/emoji/unicode/1f604.png).
|
@@ -745,7 +809,7 @@ I give this plugin two :+1:!
|
|
745
809
|
|
746
810
|
I give this plugin two :+1:!
|
747
811
|
|
748
|
-
####
|
812
|
+
#### 8.1 Emoji Customizing
|
749
813
|
|
750
814
|
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
815
|
|
@@ -757,7 +821,7 @@ jekyll-spaceship:
|
|
757
821
|
|
758
822
|
See the [Gemoji](https://github.com/github/gemoji) documentation for generating image files.
|
759
823
|
|
760
|
-
###
|
824
|
+
### 9. Modifying Element Usage
|
761
825
|
|
762
826
|
It allows us to modify elements via `CSS3 selectors`. Through it you can easily
|
763
827
|
modify the attributes of an element tag, replace the children nodes and so on,
|
@@ -844,6 +908,12 @@ jekyll-spaceship:
|
|
844
908
|
loading: eager # Replace `loading` value to `eager`
|
845
909
|
```
|
846
910
|
|
911
|
+
There are three options when using this method to lazy load images. Here are the supported values for the loading attribute:
|
912
|
+
|
913
|
+
- auto: Default lazy-loading behavior of the browser, which is the same as not including the attribute.
|
914
|
+
- lazy: Defer loading of the resource until it reaches a calculated distance from the viewport.
|
915
|
+
- eager: Load the resource immediately, regardless of where it’s located on the page.
|
916
|
+
|
847
917
|
|
848
918
|
## Credits
|
849
919
|
|
@@ -853,6 +923,7 @@ jekyll-spaceship:
|
|
853
923
|
- [jmoji](https://github.com/jekyll/jemoji) - GitHub-flavored emoji plugin for Jekyll.
|
854
924
|
- [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
925
|
- [jekyll-loading-lazy](https://github.com/gildesmarais/jekyll-loading-lazy) - Automatically adds loading="lazy" to img and iframe tags to natively load lazily.
|
926
|
+
- [mermaid](https://github.com/mermaid-js/mermaid) - Generation of diagram and flowchart from text in a similar manner as markdown.
|
856
927
|
|
857
928
|
## Contributing
|
858
929
|
|
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, video, youtube, vimeo, dailymotion, etc."
|
12
|
+
spec.summary = "A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, mermaid, emoji, video, youtube, vimeo, dailymotion, etc."
|
13
13
|
spec.homepage = "https://github.com/jeffreytse/jekyll-spaceship"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/lib/jekyll-spaceship.rb
CHANGED
@@ -8,6 +8,7 @@ module Jekyll::Spaceship
|
|
8
8
|
'table-processor',
|
9
9
|
'mathjax-processor',
|
10
10
|
'plantuml-processor',
|
11
|
+
'mermaid-processor',
|
11
12
|
'polyfill-processor',
|
12
13
|
'video-processor',
|
13
14
|
'emoji-processor',
|
@@ -35,7 +36,7 @@ module Jekyll::Spaceship
|
|
35
36
|
@@store[section] = deep_merge(default, @@store[section])
|
36
37
|
end
|
37
38
|
|
38
|
-
def self.load(config =
|
39
|
+
def self.load(config = {})
|
39
40
|
config = deep_merge(
|
40
41
|
{ CONFIG_NAME => DEFAULT_CONFIG },
|
41
42
|
config
|
@@ -50,8 +51,11 @@ module Jekyll::Spaceship
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
def self.
|
54
|
-
|
54
|
+
def self.load_config
|
55
|
+
# post load site config for `group :jekyll_plugin`
|
56
|
+
Jekyll::Hooks.register :site, :after_init do |site|
|
57
|
+
self.load(site.config)
|
58
|
+
end
|
55
59
|
end
|
56
60
|
end
|
57
61
|
end
|
@@ -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, :
|
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 = /(((?<!\\)\${1,2})[^\n]*?\1)/
|
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
|
-
|
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
|
-
:
|
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
|
@@ -7,7 +7,12 @@ require 'gemoji'
|
|
7
7
|
module Jekyll::Spaceship
|
8
8
|
class EmojiProcessor < Processor
|
9
9
|
def self.config
|
10
|
-
{
|
10
|
+
{
|
11
|
+
'css' => {
|
12
|
+
'class' => 'emoji'
|
13
|
+
},
|
14
|
+
'src' => 'https://github.githubassets.com/images/icons/emoji/'
|
15
|
+
}
|
11
16
|
end
|
12
17
|
|
13
18
|
def on_handle_html(content)
|
@@ -22,7 +27,7 @@ module Jekyll::Spaceship
|
|
22
27
|
|
23
28
|
content = content.gsub(
|
24
29
|
/(?<!\=")\s*:#{emoji_name}:\s*(?!"\s)/,
|
25
|
-
"<img class=\"
|
30
|
+
"<img class=\"\""\
|
26
31
|
" title=\":#{emoji.name}:\""\
|
27
32
|
" alt=\":#{emoji.name}:\""\
|
28
33
|
" raw=\"#{emoji.raw}\""\
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "base64"
|
5
|
+
|
6
|
+
module Jekyll::Spaceship
|
7
|
+
class MermaidProcessor < Processor
|
8
|
+
exclude :none
|
9
|
+
|
10
|
+
def self.config
|
11
|
+
{
|
12
|
+
'mode' => 'default',
|
13
|
+
'syntax' => {
|
14
|
+
'code' => 'mermaid!',
|
15
|
+
'custom' => ['@startmermaid', '@endmermaid']
|
16
|
+
},
|
17
|
+
'css' => {
|
18
|
+
'class' => 'mermaid'
|
19
|
+
},
|
20
|
+
'config': {
|
21
|
+
'theme' => 'default'
|
22
|
+
},
|
23
|
+
'src' => 'https://mermaid.ink/svg/'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def on_handle_markdown(content)
|
28
|
+
# match custom mermaid block and code block
|
29
|
+
syntax = self.config['syntax']
|
30
|
+
code_name = syntax['code']
|
31
|
+
custom = syntax['custom'][-2, 2]
|
32
|
+
|
33
|
+
patterns = [
|
34
|
+
/((`{3,})\s*#{code_name}((?:.|\n)*?)\2)/,
|
35
|
+
/((?<!\\)(#{custom[0]})((?:.|\n)*?)(?<!\\)(#{custom[1]}))/
|
36
|
+
]
|
37
|
+
|
38
|
+
patterns.each do |pattern|
|
39
|
+
content = handle_mermaid_block(pattern, content)
|
40
|
+
end
|
41
|
+
|
42
|
+
# handle escape custom mermaid block
|
43
|
+
content.gsub(/\\(#{custom[0]}|#{custom[1]})/, '\1')
|
44
|
+
end
|
45
|
+
|
46
|
+
def handle_mermaid_block(pattern, content)
|
47
|
+
content.scan pattern do |match|
|
48
|
+
match = match.select { |m| not m.nil? }
|
49
|
+
block = match[0]
|
50
|
+
code = match[2]
|
51
|
+
|
52
|
+
self.handled = true
|
53
|
+
|
54
|
+
content = content.gsub(
|
55
|
+
block,
|
56
|
+
handle_mermaid(code)
|
57
|
+
)
|
58
|
+
end
|
59
|
+
content
|
60
|
+
end
|
61
|
+
|
62
|
+
def handle_mermaid(code)
|
63
|
+
# encode to UTF-8
|
64
|
+
code = code.encode('UTF-8')
|
65
|
+
|
66
|
+
url = get_url(code)
|
67
|
+
|
68
|
+
# render mode
|
69
|
+
case self.config['mode']
|
70
|
+
when 'pre-fetch'
|
71
|
+
url = self.get_mermaid_img_data(url)
|
72
|
+
end
|
73
|
+
|
74
|
+
# return img tag
|
75
|
+
css_class = self.config['css']['class']
|
76
|
+
"<img class=\"#{css_class}\" src=\"#{url}\">"
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_url(code)
|
80
|
+
src = self.config['src']
|
81
|
+
|
82
|
+
# wrap code
|
83
|
+
code = {
|
84
|
+
'code' => code.gsub(/^\s*|\s*$/, ''),
|
85
|
+
'mermaid' => config['config']
|
86
|
+
}.to_json
|
87
|
+
|
88
|
+
# set default method
|
89
|
+
src += '{code}' if src.match(/\{.*\}/).nil?
|
90
|
+
|
91
|
+
# encode to base64 string
|
92
|
+
if src.include?('{code}')
|
93
|
+
code = Base64.urlsafe_encode64(code, padding: false)
|
94
|
+
return src.gsub('{code}', code)
|
95
|
+
else
|
96
|
+
raise "No supported src ! #{src}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_mermaid_img_data(url)
|
101
|
+
data = ''
|
102
|
+
begin
|
103
|
+
res = Net::HTTP.get_response URI(url)
|
104
|
+
raise res.body unless res.is_a?(Net::HTTPSuccess)
|
105
|
+
data = Base64.encode64(res.body)
|
106
|
+
content_type = res.header['Content-Type']
|
107
|
+
raise 'Unknown content type!' if content_type.nil?
|
108
|
+
data = "data:#{content_type};base64, #{data}"
|
109
|
+
rescue StandardError => msg
|
110
|
+
data = url
|
111
|
+
logger.log msg
|
112
|
+
end
|
113
|
+
data
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -7,23 +7,37 @@ 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
10
|
def self.config
|
16
|
-
{
|
11
|
+
{
|
12
|
+
'mode' => 'default',
|
13
|
+
'syntax' => {
|
14
|
+
'code' => 'plantuml!',
|
15
|
+
'custom' => ['@startuml', '@enduml']
|
16
|
+
},
|
17
|
+
'css' => {
|
18
|
+
'class' => 'plantuml'
|
19
|
+
},
|
20
|
+
'src' => 'http://www.plantuml.com/plantuml/png/'
|
21
|
+
}
|
17
22
|
end
|
18
23
|
|
19
24
|
def on_handle_markdown(content)
|
20
|
-
# match
|
21
|
-
|
25
|
+
# match custom plantuml block and code block
|
26
|
+
syntax = self.config['syntax']
|
27
|
+
code_name = syntax['code']
|
28
|
+
custom = syntax['custom'][-2, 2]
|
29
|
+
|
30
|
+
patterns = [
|
31
|
+
/((`{3,})\s*#{code_name}((?:.|\n)*?)\2)/,
|
32
|
+
/((?<!\\)(#{custom[0]})((?:.|\n)*?)(?<!\\)(#{custom[1]}))/
|
33
|
+
]
|
34
|
+
|
35
|
+
patterns.each do |pattern|
|
22
36
|
content = handle_plantuml_block(pattern, content)
|
23
37
|
end
|
24
38
|
|
25
|
-
# handle escape
|
26
|
-
content.gsub(/\\(
|
39
|
+
# handle escape custom plantuml block
|
40
|
+
content.gsub(/\\(#{custom[0]}|#{custom[1]})/, '\1')
|
27
41
|
end
|
28
42
|
|
29
43
|
def handle_plantuml_block(pattern, content)
|
@@ -32,11 +46,6 @@ module Jekyll::Spaceship
|
|
32
46
|
block = match[0]
|
33
47
|
code = match[2]
|
34
48
|
|
35
|
-
# skip escape default plantuml block
|
36
|
-
if block.match(/(^\\@startuml|\\@enduml$)/)
|
37
|
-
next
|
38
|
-
end
|
39
|
-
|
40
49
|
self.handled = true
|
41
50
|
|
42
51
|
content = content.gsub(
|
@@ -51,21 +60,43 @@ module Jekyll::Spaceship
|
|
51
60
|
# wrap plantuml code
|
52
61
|
code = "@startuml#{code}@enduml".encode('UTF-8')
|
53
62
|
|
54
|
-
|
55
|
-
|
56
|
-
|
63
|
+
url = get_url(code)
|
64
|
+
|
65
|
+
# render mode
|
66
|
+
case self.config['mode']
|
67
|
+
when 'pre-fetch'
|
68
|
+
url = self.get_plantuml_img_data(url)
|
69
|
+
end
|
57
70
|
|
58
71
|
# return img tag
|
59
|
-
|
72
|
+
css_class = self.config['css']['class']
|
73
|
+
"<img class=\"#{css_class}\" src=\"#{url}\">"
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_url(code)
|
77
|
+
src = self.config['src']
|
78
|
+
|
79
|
+
# set default method
|
80
|
+
src += '{hexcode}' if src.match(/\{.*\}/).nil?
|
81
|
+
|
82
|
+
# encode to hex string
|
83
|
+
if src.include?('{hexcode}')
|
84
|
+
code = '~h' + code.unpack("H*").first
|
85
|
+
return src.gsub('{hexcode}', code)
|
86
|
+
else
|
87
|
+
raise "No supported src ! #{src}"
|
88
|
+
end
|
60
89
|
end
|
61
90
|
|
62
|
-
def get_plantuml_img_data(
|
91
|
+
def get_plantuml_img_data(url)
|
63
92
|
data = ''
|
64
|
-
url = "#{config['src']}#{code}"
|
65
93
|
begin
|
66
|
-
|
67
|
-
|
68
|
-
data =
|
94
|
+
res = Net::HTTP.get_response URI(url)
|
95
|
+
raise res.body unless res.is_a?(Net::HTTPSuccess)
|
96
|
+
data = Base64.encode64(res.body)
|
97
|
+
content_type = res.header['Content-Type']
|
98
|
+
raise 'Unknown content type!' if content_type.nil?
|
99
|
+
data = "data:#{content_type};base64, #{data}"
|
69
100
|
rescue StandardError => msg
|
70
101
|
data = url
|
71
102
|
logger.log msg
|
@@ -8,15 +8,15 @@ module Jekyll::Spaceship
|
|
8
8
|
def on_handle_markdown(content)
|
9
9
|
# pre-handle reference-style links
|
10
10
|
references = {}
|
11
|
-
content.scan(
|
11
|
+
content.scan(/\n\s*(\[(.*)\]:\s*(\S+(\s+".*?")?))/) do |match_data|
|
12
12
|
ref_name = match_data[1]
|
13
13
|
ref_value = match_data[2]
|
14
14
|
references[ref_name] = ref_value
|
15
15
|
end
|
16
16
|
if references.size > 0
|
17
|
-
content.scan(
|
17
|
+
content.scan(/[^\n]*(?<!\\)\|[^\n]*/) do |result|
|
18
18
|
references.each do |key, val|
|
19
|
-
replace = result.gsub(/\[(
|
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,18 +24,21 @@ module Jekyll::Spaceship
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# pre-handle row-span
|
27
|
-
content = content.gsub(/(?<!\\)(
|
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(/((?<!\\)
|
31
|
+
.gsub(/\\:(?=[^\n]*?(?<!\\)\|)/, '\\\\\\\\:')
|
32
|
+
.gsub(/((?<!\\)\|[^\n]*?)(\\:)/, '\1\\\\\\\\:')
|
33
33
|
|
34
34
|
# escape * and _ and $ etc.
|
35
|
-
content.scan(
|
35
|
+
content.scan(/[^\n]*(?<!\\)\|[^\n]*/) do |result|
|
36
|
+
# skip for math expression within pipeline
|
37
|
+
next unless result
|
38
|
+
.gsub(/((?<!\\)\${1,2})[^\n]*?\1/, '')
|
39
|
+
.match(/(?<!\\)\|/)
|
36
40
|
replace = result.gsub(
|
37
|
-
/(?<!(?<!\\)\\)(\*|\$|\[|\(|\"|_)/,
|
38
|
-
'\\\\\\\\\1')
|
41
|
+
/(?<!(?<!\\)\\)(\*|\$|\[|\(|\"|_)/, '\\\\\\\\\1')
|
39
42
|
next if result == replace
|
40
43
|
content = content.gsub(result, replace)
|
41
44
|
end
|
@@ -50,6 +53,7 @@ module Jekyll::Spaceship
|
|
50
53
|
|
51
54
|
# handle each table
|
52
55
|
doc.css('table').each do |table|
|
56
|
+
next if table.ancestors('code, pre').size > 0
|
53
57
|
rows = table.css('tr')
|
54
58
|
data.table = table
|
55
59
|
data.rows = rows
|
@@ -4,6 +4,20 @@ require 'uri'
|
|
4
4
|
|
5
5
|
module Jekyll::Spaceship
|
6
6
|
class VideoProcessor < Processor
|
7
|
+
def self.config
|
8
|
+
{
|
9
|
+
'default' => {
|
10
|
+
'id' => 'video-{id}',
|
11
|
+
'class' => 'video',
|
12
|
+
'width' => '100%',
|
13
|
+
'height' => 350,
|
14
|
+
'border' => 0,
|
15
|
+
'style' => 'max-width: 600px',
|
16
|
+
'allow' => 'encrypted-media; picture-in-picture',
|
17
|
+
}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
7
21
|
def on_handle_markdown(content)
|
8
22
|
content = handle_normal_video(content)
|
9
23
|
content = handle_youtube(content)
|
@@ -87,13 +101,17 @@ module Jekyll::Spaceship
|
|
87
101
|
next true if v == id or v == ''
|
88
102
|
end
|
89
103
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
104
|
+
default = self.config['default']
|
105
|
+
css_id = qs['id'] || default['id']
|
106
|
+
css_class = qs['class'] || default['class']
|
107
|
+
width = qs['width'] || data[:width] || default['width']
|
108
|
+
height = qs['height'] || data[:height] || default['height']
|
109
|
+
frameborder = qs['frameborder'] || default['border']
|
110
|
+
style = qs['style'] || default['style']
|
111
|
+
allow = qs['allow'] || default['allow']
|
112
|
+
|
113
|
+
css_id = css_id.gsub('{id}', id)
|
114
|
+
css_class = css_class.gsub('{id}', id)
|
97
115
|
|
98
116
|
url = URI(iframe_url ? "#{iframe_url}#{id}" : url).tap do |v|
|
99
117
|
v.query = URI.encode_www_form(qs) if qs.size > 0
|
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.8.3
|
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-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- lib/jekyll-spaceship/processors/element-processor.rb
|
141
141
|
- lib/jekyll-spaceship/processors/emoji-processor.rb
|
142
142
|
- lib/jekyll-spaceship/processors/mathjax-processor.rb
|
143
|
+
- lib/jekyll-spaceship/processors/mermaid-processor.rb
|
143
144
|
- lib/jekyll-spaceship/processors/plantuml-processor.rb
|
144
145
|
- lib/jekyll-spaceship/processors/polyfill-processor.rb
|
145
146
|
- lib/jekyll-spaceship/processors/table-processor.rb
|
@@ -173,5 +174,5 @@ rubygems_version: 2.7.7
|
|
173
174
|
signing_key:
|
174
175
|
specification_version: 4
|
175
176
|
summary: A Jekyll plugin to provide powerful supports for table, mathjax, plantuml,
|
176
|
-
emoji, video, youtube, vimeo, dailymotion, etc.
|
177
|
+
mermaid, emoji, video, youtube, vimeo, dailymotion, etc.
|
177
178
|
test_files: []
|