jekyll-spaceship 0.7.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: 38acd43c5d713728eb8beefc21a41ccff0404503138429c5fc695d5a92b0fbb5
4
- data.tar.gz: aa0e6b588b3f778ef332ec83604ba26a3d238de34bfb458a7f85d1c3b006c0f5
3
+ metadata.gz: 419f539c81e8313699cf1e0798cdffe004a0f04f53845f3d72f6f7df18b072ed
4
+ data.tar.gz: bad98cd8ba939cf7c370841f12f4d56b01d78df306cb7e5143f68a8f53055123
5
5
  SHA512:
6
- metadata.gz: 53ad3ff1458d8b5a1cde457ec7fa34672680f334fddb1613ebec356a461f0c7217faea14e361f0e022b3dceb7789d0ff7fa5d069d95c190343008d9485630f76
7
- data.tar.gz: 97606894a42e2fa2fc34e66fb9b3cbb6013587696ed70bf8153a9b5bd2cf81f6444ee9337d13d672f3c3afe3c504039fd754b51deee9324c3df6287bee7c6b53
6
+ metadata.gz: d3973afe5641351d205e473ba2ae3f61bb9daf14aab803602fe6b0e94dc8cf0f14603f09e5f0704f94612e9bcd65deec972d5b5567840ee63c822bb62fe80f8f
7
+ data.tar.gz: 647e60a7b13b26ea6053dc184f440d971aa4055a70ef7d6dc4d661061b513a28012f9815676f2ad75cd04030023e6d0dd3f4330336c0e6304d9fa7fe53279603
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. Video Usage](#4-video-usage)
109
- - [4.1 Youtube Usage](#youtube-usage)
110
- - [4.2 Vimeo Usage](#vimeo-usage)
111
- - [4.3 DailyMotion Usage](#dailymotion-usage)
112
- - [4.4 General Video Usage](#general-video-usage)
113
- - [5. Hybrid HTML with Markdown](#5-hybrid-html-with-markdown)
114
- - [6. Markdown Polyfill](#6-markdown-polyfill)
115
- - [6.1 Escape Ordered List](#escape-ordered-list)
116
- - [7. Emoji Usage](#7-emoji-usage)
117
- - [7.1 Emoji Customizing](#71-emoji-customizing)
118
- - [8. Modifying Element Usage](#8-modifying-element-usage)
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)
@@ -148,10 +149,12 @@ This plugin runs with the following configuration options by default. Alternativ
148
149
  ```yml
149
150
  # Where things are
150
151
  jekyll-spaceship:
152
+ # default enabled processors
151
153
  processors:
152
154
  - table-processor
153
155
  - mathjax-processor
154
156
  - plantuml-processor
157
+ - mermaid-processor
155
158
  - polyfill-processor
156
159
  - video-processor
157
160
  - emoji-processor
@@ -164,8 +167,35 @@ jekyll-spaceship:
164
167
  - ['$','$']
165
168
  - ['\(','\)']
166
169
  plantuml-processor:
170
+ mode: default # mode value 'pre-fetch' for fetching image at building stage
171
+ css:
172
+ class: plantuml
173
+ syntax:
174
+ code: 'plantuml!'
175
+ custom: ['@startuml', '@enduml']
167
176
  src: http://www.plantuml.com/plantuml/png/
177
+ mermaid-processor:
178
+ mode: default # mode value 'pre-fetch' for fetching image at building stage
179
+ css:
180
+ class: mermaid
181
+ syntax:
182
+ code: 'mermaid!'
183
+ custom: ['@startmermaid', '@endmermaid']
184
+ config:
185
+ theme: default
186
+ src: https://mermaid.ink/svg/
187
+ video-processor:
188
+ default:
189
+ id: 'video-{id}'
190
+ class: 'video'
191
+ width: '100%'
192
+ height: 350
193
+ border: 0
194
+ style: 'max-width: 600px'
195
+ allow: 'encrypted-media; picture-in-picture'
168
196
  emoji-processor:
197
+ css:
198
+ class: emoji
169
199
  src: https://github.githubassets.com/images/icons/emoji/
170
200
  ```
171
201
 
@@ -191,13 +221,13 @@ This feature is contributed by [pmccloghrylaing](https://github.com/pmccloghryla
191
221
  ```markdown
192
222
  | Stage | Direct Products | ATP Yields |
193
223
  | -----------------: | --------------: | ---------: |
194
- | Glycolysis | 2 ATP | |
195
- | ^^ | 2 NADH | 3--5 ATP |
224
+ | Glycolysis | 2 ATP ||
225
+ | ^^ | 2 NADH | 3--5 ATP |
196
226
  | Pyruvaye oxidation | 2 NADH | 5 ATP |
197
227
  | Citric acid cycle | 2 ATP ||
198
- | ^^ | 6 NADH | 15 ATP |
199
- | ^^ | 2 FADH | 3 ATP |
200
- | 30--32 ATP |||
228
+ | ^^ | 6 NADH | 15 ATP |
229
+ | ^^ | 2 FADH | 3 ATP |
230
+ | 30--32 ATP |||
201
231
  ```
202
232
 
203
233
  Code above would be parsed as:
@@ -398,7 +428,7 @@ Table cell can be set alignment separately.
398
428
  ```markdown
399
429
  | : Fruits \|\| Food : |||
400
430
  | :--------- | :-------- | :-------- |
401
- | Apple | : Apple :| Apple \
431
+ | Apple | : Apple : | Apple \
402
432
  | Banana | Banana | Banana \
403
433
  | Orange | Orange | Orange |
404
434
  | : Rowspan is 4 : || How's it? |
@@ -546,13 +576,13 @@ Code above would be parsed as:
546
576
  - class diagram,
547
577
  - activity diagram,
548
578
  - component diagram,
549
- - state diagram
579
+ - state diagram,
550
580
  - object diagram
551
581
 
552
582
  There are two ways to create a diagram in your Jekyll blog page:
553
583
 
554
- ````markdown
555
- ```plantuml
584
+ ````
585
+ ```plantuml!
556
586
  Bob -> Alice : hello world
557
587
  ```
558
588
  ````
@@ -569,7 +599,48 @@ Code above would be parsed as:
569
599
 
570
600
  ![PlantUML Diagram](https://user-images.githubusercontent.com/9413601/82813883-9180b300-9ec8-11ea-8778-f450e0056938.png)
571
601
 
572
- ### 4. Video Usage
602
+ ### 4. Mermaid Usage
603
+
604
+ [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.
605
+
606
+ It allows to quickly write:
607
+
608
+ - flow chart,
609
+ - pie chart,
610
+ - sequence diagram,
611
+ - class diagram,
612
+ - state diagram,
613
+ - entity relationship diagram,
614
+ - user journey,
615
+ - gantt
616
+
617
+ There are two ways to create a diagram in your Jekyll blog page:
618
+
619
+ ````
620
+ ```mermaid!
621
+ pie title Pets adopted by volunteers
622
+ "Dogs" : 386
623
+ "Cats" : 85
624
+ "Rats" : 35
625
+ ```
626
+ ````
627
+
628
+ or
629
+
630
+ ```markdown
631
+ @startmermaid
632
+ pie title Pets adopted by volunteers
633
+ "Dogs" : 386
634
+ "Cats" : 85
635
+ "Rats" : 35
636
+ @endmermaid
637
+ ```
638
+
639
+ Code above would be parsed as:
640
+
641
+ ![Mermaid Diagram](https://user-images.githubusercontent.com/9413601/85282355-2e317300-b4be-11ea-9c30-8f9d61540d14.png)
642
+
643
+ ### 5. Video Usage
573
644
 
574
645
  How often did you find yourself googling "**How to embed a video in markdown?**"
575
646
 
@@ -603,9 +674,7 @@ the link as below:
603
674
 
604
675
  ```markdown
605
676
  ![](https://www.youtube.com/watch?v=Ptk_1Dc2iPY?width=800&height=500)
606
- ```
607
677
 
608
- ```markdown
609
678
  ![](https://www.dailymotion.com/video/x7tfyq3?width=100%&height=400&autoplay=1)
610
679
  ```
611
680
 
@@ -613,9 +682,7 @@ the link as below:
613
682
 
614
683
  ```markdown
615
684
  ![](https://www.youtube.com/watch?v=Ptk_1Dc2iPY)
616
- ```
617
685
 
618
- ```markdown
619
686
  ![](//www.youtube.com/watch?v=Ptk_1Dc2iPY?width=800&height=500)
620
687
  ```
621
688
 
@@ -623,9 +690,7 @@ the link as below:
623
690
 
624
691
  ```markdown
625
692
  ![](https://vimeo.com/263856289)
626
- ```
627
693
 
628
- ```markdown
629
694
  ![](https://vimeo.com/263856289?width=500&height=320)
630
695
  ```
631
696
 
@@ -633,9 +698,7 @@ the link as below:
633
698
 
634
699
  ```markdown
635
700
  ![](https://www.dailymotion.com/video/x7tfyq3)
636
- ```
637
701
 
638
- ```markdown
639
702
  ![](https://dai.ly/x7tgcev?width=100%&height=400)
640
703
  ```
641
704
 
@@ -643,18 +706,14 @@ the link as below:
643
706
 
644
707
  ```markdown
645
708
  ![](//www.html5rocks.com/en/tutorials/video/basics/devstories.webm)
646
- ```
647
709
 
648
- ```markdown
649
710
  ![](//techslides.com/demos/sample-videos/small.ogv?allow=autoplay)
650
- ```
651
711
 
652
- ```markdown
653
712
  ![](//techslides.com/demos/sample-videos/small.mp4?width=400)
654
713
  ```
655
714
 
656
715
 
657
- ### 5. Hybrid HTML with Markdown
716
+ ### 6. Hybrid HTML with Markdown
658
717
 
659
718
  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
719
 
@@ -668,7 +727,7 @@ It's easy to write markdown inside HTML:
668
727
 
669
728
  | : Fruits \|\| Food : |||
670
729
  | :--------- | :-------- | :-------- |
671
- | Apple | : Apple :| Apple \
730
+ | Apple | : Apple : | Apple \
672
731
  | Banana | Banana | Banana \
673
732
  | Orange | Orange | Orange |
674
733
  | : Rowspan is 4 : || How's it? |
@@ -688,7 +747,7 @@ Bob -> Alice : hello
688
747
  </script>
689
748
  ```
690
749
 
691
- ### 6. Markdown Polyfill
750
+ ### 7. Markdown Polyfill
692
751
 
693
752
  It allows us to polyfill features for extending markdown syntax.
694
753
 
@@ -696,7 +755,7 @@ It allows us to polyfill features for extending markdown syntax.
696
755
 
697
756
  - Escape ordered list
698
757
 
699
- #### Escape Ordered List
758
+ #### 7.1 Escape Ordered List
700
759
 
701
760
  A backslash at begin to escape the ordered list.
702
761
 
@@ -730,7 +789,7 @@ Escaped:
730
789
  10. List item Cafe.
731
790
  ```
732
791
 
733
- ### 7. Emoji Usage
792
+ ### 8. Emoji Usage
734
793
  GitHub-flavored emoji images and names would allow emojifying content such as: it's raining :cat:s and :dog:s!
735
794
 
736
795
  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 +804,7 @@ I give this plugin two :+1:!
745
804
 
746
805
  I give this plugin two :+1:!
747
806
 
748
- #### 7.1 Emoji Customizing
807
+ #### 8.1 Emoji Customizing
749
808
 
750
809
  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
810
 
@@ -757,7 +816,7 @@ jekyll-spaceship:
757
816
 
758
817
  See the [Gemoji](https://github.com/github/gemoji) documentation for generating image files.
759
818
 
760
- ### 8. Modifying Element Usage
819
+ ### 9. Modifying Element Usage
761
820
 
762
821
  It allows us to modify elements via `CSS3 selectors`. Through it you can easily
763
822
  modify the attributes of an element tag, replace the children nodes and so on,
@@ -844,6 +903,12 @@ jekyll-spaceship:
844
903
  loading: eager # Replace `loading` value to `eager`
845
904
  ```
846
905
 
906
+ There are three options when using this method to lazy load images. Here are the supported values for the loading attribute:
907
+
908
+ - auto: Default lazy-loading behavior of the browser, which is the same as not including the attribute.
909
+ - lazy: Defer loading of the resource until it reaches a calculated distance from the viewport.
910
+ - eager: Load the resource immediately, regardless of where it’s located on the page.
911
+
847
912
 
848
913
  ## Credits
849
914
 
@@ -853,6 +918,7 @@ jekyll-spaceship:
853
918
  - [jmoji](https://github.com/jekyll/jemoji) - GitHub-flavored emoji plugin for Jekyll.
854
919
  - [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
920
  - [jekyll-loading-lazy](https://github.com/gildesmarais/jekyll-loading-lazy) - Automatically adds loading="lazy" to img and iframe tags to natively load lazily.
921
+ - [mermaid](https://github.com/mermaid-js/mermaid) - Generation of diagram and flowchart from text in a similar manner as markdown.
856
922
 
857
923
  ## Contributing
858
924
 
@@ -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
 
@@ -8,5 +8,5 @@ require 'jekyll-spaceship/cores/register'
8
8
 
9
9
  module Jekyll::Spaceship
10
10
  Logger.display_info
11
- Config.load
11
+ Config.load_config
12
12
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'yaml'
4
-
5
3
  module Jekyll::Spaceship
6
4
  class Config
7
5
  CONFIG_NAME = 'jekyll-spaceship'
@@ -10,6 +8,7 @@ module Jekyll::Spaceship
10
8
  'table-processor',
11
9
  'mathjax-processor',
12
10
  'plantuml-processor',
11
+ 'mermaid-processor',
13
12
  'polyfill-processor',
14
13
  'video-processor',
15
14
  'emoji-processor',
@@ -33,12 +32,11 @@ module Jekyll::Spaceship
33
32
  end
34
33
 
35
34
  def self.store(section, default)
36
- return if @@store[section].nil?
37
35
  return @@store[section] if default.nil?
38
36
  @@store[section] = deep_merge(default, @@store[section])
39
37
  end
40
38
 
41
- def self.load(config = self.site_config)
39
+ def self.load(config = {})
42
40
  config = deep_merge(
43
41
  { CONFIG_NAME => DEFAULT_CONFIG },
44
42
  config
@@ -53,8 +51,11 @@ module Jekyll::Spaceship
53
51
  end
54
52
  end
55
53
 
56
- def self.site_config
57
- Jekyll.sites.first.config
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
58
59
  end
59
60
  end
60
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, :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
@@ -7,7 +7,12 @@ require 'gemoji'
7
7
  module Jekyll::Spaceship
8
8
  class EmojiProcessor < Processor
9
9
  def self.config
10
- { 'src' => 'https://github.githubassets.com/images/icons/emoji/' }
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=\"emoji\""\
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
- { 'src' => 'http://www.plantuml.com/plantuml/png/' }
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 default plantuml block and code block
21
- PLANTUML_PATTERNS.each do |pattern|
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 default plantuml block
26
- content.gsub(/\\(@startuml|@enduml)/, '\1')
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
- # encode to hex string
55
- code = '~h' + code.unpack("H*").first
56
- data = self.get_plantuml_img_data(code)
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
- "<img class=\"plantuml\" src=\"#{data}\">"
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(code)
91
+ def get_plantuml_img_data(url)
63
92
  data = ''
64
- url = "#{config['src']}#{code}"
65
93
  begin
66
- data = Net::HTTP.get URI(url)
67
- data = Base64.encode64(data)
68
- data = "data:image/png;base64, #{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
@@ -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
@@ -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
- 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"
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Spaceship
5
- VERSION = "0.7.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.7.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-18 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
@@ -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: []