jekyll-spaceship 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1eb92f8cf62c528dec112c2cd8a00c7721751942d635065fbfb6c73736c3df9a
4
- data.tar.gz: 3c6a315b49882a071dfd0b85bf55197023156855bd618360f33e27564b77823c
3
+ metadata.gz: f948e78348f6b74d101dff999356e1188dc973cdc7e1eb697f74777406755ce0
4
+ data.tar.gz: cfae2fbfc444d4db48c1c68824c96fd6d8c4cf4ca1f3b01c5c987fff252673a0
5
5
  SHA512:
6
- metadata.gz: bb0565056cbdb3df43cab239326364e680bba9ef87068ca1e823c24cfc03a77495c8e29efb4d2df0c51b68a0c9cc95fa1a450860cc1bdeaf91ffd3d164118733
7
- data.tar.gz: a033c89fbda99d63221689e07089cc3875304e74b08332bb1c91599476302ebbaa8ce91876072996811191bcaf84dc92e5f8bc5864153bdd953b588aa4e9831d
6
+ metadata.gz: 65e2c45a6b175cb712c4900644537d53fa6fd73632c8a7f685dcd83d4e1a019adfcb5c7e3ee6f5b7053de16556cf5e73d9ffee0f07bd908a9f2565f1843dbc11
7
+ data.tar.gz: 68f7e48bc2f10217c99a2bf7f75530dedceb1cf90a062d1bdfe80d6c0951af058ca5708059ceca03c9206a6c253eb71334ca11efa2fff4a69135101d5941b56b
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Code Climate](https://codeclimate.com/github/jeffreytse/jekyll-spaceship/badges/gpa.svg)](https://codeclimate.com/github/jeffreytse/jekyll-spaceship)
6
6
  [![Test Coverage](https://api.codeclimate.com/v1/badges/cd56b207f327603662a1/test_coverage)](https://codeclimate.com/github/jeffreytse/jekyll-spaceship/test_coverage)
7
7
 
8
- A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, etc.
8
+ A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, youtube, etc.
9
9
 
10
10
  ## Table of Contents
11
11
 
@@ -17,14 +17,23 @@ A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, etc.
17
17
  - [1.2 Multiline](#multiline)
18
18
  - [1.3 Headerless](#headerless)
19
19
  - [1.4 Cell Alignment](#cell-alignment)
20
+ - [1.5 Cell Markdown](#cell-markdown)
20
21
  - [2. MathJax Usage](#2-mathjax-usage)
21
22
  - [3. PlantUML Usage](#3-plantuml-usage)
23
+ - [4. Video Usage](#4-video-usage)
24
+ - [4.1 Youtube Usage](#youtube-usage)
25
+ - [4.2 Vimeo Usage](#vimeo-usage)
26
+ - [4.3 DailyMotion Usage](#dailymotion-usage)
27
+ - [5. Hybrid HTML with Markdown](#5-hybrid-html-with-markdown)
28
+ - [6. Markdown Polyfill](#6-markdown-polyfill)
29
+ - [6.1 Escape Ordered List](#escape-ordered-list)
22
30
  - [Credits](#credits)
23
31
  - [Contributing](#contributing)
24
32
  - [License](#license)
25
33
 
26
34
  ## Requirements
27
- * Ruby >= 2.3.0
35
+
36
+ - Ruby >= 2.3.0
28
37
 
29
38
  ## Installation
30
39
 
@@ -47,28 +56,29 @@ plugins:
47
56
 
48
57
  **For now, these extended features are provided:**
49
58
 
50
- * Cells spanning multiple columns
51
- * Cells spanning multiple rows
52
- * Cells text align separately
53
- * Table header not required
54
- * Grouped table header rows or data rows
59
+ - Cells spanning multiple columns
60
+ - Cells spanning multiple rows
61
+ - Cells text align separately
62
+ - Table header not required
63
+ - Grouped table header rows or data rows
55
64
 
56
65
  Noted that GitHub filters out style property, so the example displays with the obsolete align property. But in actual this plugin outputs style property with text-align CSS attribute.
57
66
 
58
67
  #### Rowspan and Colspan
68
+
59
69
  ^^ in a cell indicates it should be merged with the cell above.
60
70
  This feature is contributed by [pmccloghrylaing](https://github.com/pmccloghrylaing).
61
71
 
62
72
  ```markdown
63
- | Stage | Direct Products | ATP Yields |
64
- | ----: | --------------: | ---------: |
65
- |Glycolysis | 2 ATP ||
66
- |^^ | 2 NADH | 3--5 ATP |
67
- |Pyruvaye oxidation | 2 NADH | 5 ATP |
68
- |Citric acid cycle | 2 ATP | |
69
- |^^ | 6 NADH | 15 ATP |
70
- |^^ | 2 FADH | 3 ATP |
71
- | 30--32 ATP |||
73
+ | Stage | Direct Products | ATP Yields |
74
+ | -----------------: | --------------: | ---------: |
75
+ | Glycolysis | 2 ATP | |
76
+ | ^^ | 2 NADH | 3--5 ATP |
77
+ | Pyruvaye oxidation | 2 NADH | 5 ATP |
78
+ | Citric acid cycle | 2 ATP ||
79
+ | ^^ | 6 NADH | 15 ATP |
80
+ | ^^ | 2 FADH | 3 ATP |
81
+ | 30--32 ATP |||
72
82
  ```
73
83
 
74
84
  Code above would be parsed as:
@@ -114,18 +124,19 @@ Code above would be parsed as:
114
124
  </table>
115
125
 
116
126
  #### Multiline
127
+
117
128
  A backslash at end to join cell contents with the following lines.
118
129
  This feature is contributed by [Lucas-C](https://github.com/Lucas-C).
119
130
 
120
131
  ```markdown
121
- |: Easy Multiline :|||
122
- |:------ |:------ |:-------- |
123
- | Apple | Banana | Orange \
124
- | Apple | Banana | Orange \
125
- | Apple | Banana | Orange
126
- | Apple | Banana | Orange \
127
- | Apple | Banana | Orange |
128
- | Apple | Banana | Orange |
132
+ | : Easy Multiline : |||
133
+ | :----- | :----- | :------ |
134
+ | Apple | Banana | Orange \
135
+ | Apple | Banana | Orange \
136
+ | Apple | Banana | Orange
137
+ | Apple | Banana | Orange \
138
+ | Apple | Banana | Orange |
139
+ | Apple | Banana | Orange |
129
140
  ```
130
141
 
131
142
  Code above would be parsed as:
@@ -156,18 +167,19 @@ Code above would be parsed as:
156
167
  </table>
157
168
 
158
169
  #### Headerless
170
+
159
171
  Table header can be eliminated.
160
172
 
161
173
  ```markdown
162
174
  |--|--|--|--|--|--|--|--|
163
- |♜| |♝|♛|♚|♝|♞|♜|
164
- | |♟|♟|♟| |♟|♟|♟|
165
- |♟| |♞| | | | | |
166
- | |♗| | |♟| | | |
167
- | | | | |♙| | | |
168
- | | | | | |♘| | |
169
- |♙|♙|♙|♙| |♙|♙|♙|
170
- |♖|♘|♗|♕|♔| | |♖|
175
+ |♜| |♝|♛|♚|♝|♞|♜|
176
+ | |♟|♟|♟| |♟|♟|♟|
177
+ |♟| |♞| | | | | |
178
+ | |♗| | |♟| | | |
179
+ | | | | |♙| | | |
180
+ | | | | | |♘| | |
181
+ |♙|♙|♙|♙| |♙|♙|♙|
182
+ |♖|♘|♗|♕|♔| | |♖|
171
183
  ```
172
184
 
173
185
  Code above would be parsed as:
@@ -258,21 +270,22 @@ Code above would be parsed as:
258
270
  </table>
259
271
 
260
272
  #### Cell Alignment
273
+
261
274
  Markdown table syntax use colons ":" for forcing column alignment.
262
- Therefore, here we also use it for foring cell alignment.
275
+ Therefore, here we also use it for foring cell alignment.
263
276
 
264
277
  Table cell can be set alignment separately.
265
278
 
266
- ```
267
- |: Fruits \|\| Food :|||
268
- |:-------- |:-------- |:------------ |
269
- | Apple |: Apple :| Apple \
270
- | Banana | Banana | Banana \
271
- | Orange | Orange | Orange |
272
- |: Rowspan is 4 :|| How's it? |
273
- |^^ A. Peach || 1. Fine :|
274
- |^^ B. Orange ||^^ 2. Bad |
275
- |^^ C. Banana || It's OK! |
279
+ ```markdown
280
+ | : Fruits \|\| Food : |||
281
+ | :--------- | :-------- | :-------- |
282
+ | Apple | : Apple :| Apple \
283
+ | Banana | Banana | Banana \
284
+ | Orange | Orange | Orange |
285
+ | : Rowspan is 4 : || How's it? |
286
+ |^^ A. Peach || 1. Fine :|
287
+ |^^ B. Orange ||^^ 2. Bad |
288
+ |^^ C. Banana || It's OK! |
276
289
  ```
277
290
 
278
291
  Code above would be parsed as:
@@ -309,22 +322,79 @@ Rowspan is 4
309
322
  </tbody>
310
323
  </table>
311
324
 
325
+ #### Cell Markdown
326
+
327
+ Sometimes we may need some abundant content (e.g., mathjax, image, video) in Markdown table
328
+ Therefore, here we also make markown syntax possible inside a cell.
329
+
330
+ ```markdown
331
+ | : MathJax \|\| Image : |||
332
+ | :------------ | :-------- | :----------------------------- |
333
+ | Apple | : Apple : | Apple \
334
+ | Banana | Banana | Banana \
335
+ | Orange | Orange | Orange |
336
+ | : Rowspan is 4 : || : How's it? : |
337
+ | ^^ A. Peach || 1. ![example][cell-image] |
338
+ | ^^ B. Orange || ^^ 2. $I = \int \rho R^{2} dV$ |
339
+ | ^^ C. Banana || **It's OK!** |
340
+
341
+ [cell-image]: https://jekyllrb.com/img/octojekyll.png "An exemplary image"
342
+ ```
343
+
344
+ Code above would be parsed as:
345
+
346
+ <table>
347
+ <thead>
348
+ <tr>
349
+ <th align="center" colspan="3">MathJax || Image
350
+ </tr>
351
+ </thead>
352
+ <tbody>
353
+ <tr>
354
+ <td align="left">Apple<br>Banana<br>Orange</td>
355
+ <td align="center">Apple<br>Banana<br>Orange</td>
356
+ <td align="left">Apple<br>Banana<br>Orange</td>
357
+ </tr>
358
+ <tr>
359
+ <td align="center" rowspan="4" colspan="2">
360
+ Rowspan is 4
361
+ <br>A. Peach
362
+ <br>B. Orange
363
+ <br>C. Banana
364
+ </td>
365
+ </tr>
366
+ <tr>
367
+ <td align="center">How's it?</td>
368
+ </tr>
369
+ <tr>
370
+ <td align="left">
371
+ <ol>
372
+ <li><img width="100" src="http://latex2png.com/pngs/82b913db54a9f303bed7197d11347d74.png"></img></li>
373
+ <li><img width="150" src="https://jekyllrb.com/img/octojekyll.png" title="An exemplary image"></img></li>
374
+ </ol>
375
+ </td>
376
+ </tr>
377
+ <tr>
378
+ <td align="left"><b>It' OK!</b></td>
379
+ </tr>
380
+ </tbody>
381
+ </table>
312
382
 
313
383
  ### 2. MathJax Usage
384
+
314
385
  [MathJax](http://www.mathjax.org/) is an open-source JavaScript display engine for LaTeX, MathML, and AsciiMath notation that works in all modern browsers.
315
386
 
316
387
  **Some of the main features of MathJax include:**
317
388
 
318
- * High-quality display of LaTeX, MathML, and AsciiMath notation in HTML pages
319
- * Supported in most browsers with no plug-ins, extra fonts, or special
389
+ - High-quality display of LaTeX, MathML, and AsciiMath notation in HTML pages
390
+ - Supported in most browsers with no plug-ins, extra fonts, or special
320
391
  setup for the reader
321
- * Easy for authors, flexible for publishers, extensible for developers
322
- * Supports math accessibility, cut-and-paste interoperability, and other
392
+ - Easy for authors, flexible for publishers, extensible for developers
393
+ - Supports math accessibility, cut-and-paste interoperability, and other
323
394
  advanced functionality
324
- * Powerful API for integration with other web applications
325
-
395
+ - Powerful API for integration with other web applications
326
396
 
327
- Put your math expression within \$...\$
397
+ Put your math expression within \\\\\\\\\$...\$
328
398
 
329
399
  ```markdown
330
400
  $ a * b = c ^ b $
@@ -339,31 +409,177 @@ $ \int\_a^b f(x)\,dx. $
339
409
  ```
340
410
 
341
411
  ### 3. PlantUML Usage
412
+
342
413
  [PlantUML](http://plantuml.sourceforge.net/) is a component that allows to quickly write:
343
- * sequence diagram,
344
- * use case diagram,
345
- * class diagram,
346
- * activity diagram,
347
- * component diagram,
348
- * state diagram
349
- * object diagram
350
414
 
415
+ - sequence diagram,
416
+ - use case diagram,
417
+ - class diagram,
418
+ - activity diagram,
419
+ - component diagram,
420
+ - state diagram
421
+ - object diagram
351
422
 
352
423
  There are two ways to create a diagram in your Jekyll blog page:
353
424
 
425
+ ````markdown
426
+ ```plantuml
427
+ Bob -> Alice : hello world
428
+ ```
429
+ ````
430
+
431
+ or
432
+
354
433
  ```markdown
355
434
  @startuml
356
435
  Bob -> Alice : hello
357
436
  @enduml
358
437
  ```
359
438
 
360
- or
439
+ ### 4. Video Usage
361
440
 
362
- ````markdown
363
- ``` plantuml
364
- Bob -> Alice : hello world
441
+ How often did you find yourself googling "**How to embed a video in markdown?**"
442
+
443
+ While its not possible to embed a video in markdown, the best and easiest way is to extract a frame from the video. To add videos to your markdown files easier I developped this tool for you, and it will parse the video link inside the image block automatically.
444
+
445
+ **For now, these video links parsing are provided:**
446
+
447
+ - Youtube
448
+ - Vimeo
449
+ - DailyMotion
450
+
451
+ There are two ways to embed a video in your Jekyll blog page:
452
+
453
+ Inline-style:
454
+
455
+ ```markdown
456
+ ![]({video-link})
457
+ ```
458
+
459
+ Reference-style:
460
+
461
+ ```markdown
462
+ ![][{reference}]
463
+
464
+ [{reference}]: {video-link}
465
+ ```
466
+
467
+ For configuring video attributes (e.g, width, height), just adding query string to
468
+ the link as below:
469
+
470
+ ```markdown
471
+ ![](https://www.youtube.com/watch?v=Ptk_1Dc2iPY?width=800&height=500)
472
+ ```
473
+
474
+ ```markdown
475
+ ![](https://www.dailymotion.com/video/x7tfyq3?width=100%&height=400)
476
+ ```
477
+
478
+ #### Youtube Usage
479
+
480
+ ```markdown
481
+ ![](https://www.youtube.com/watch?v=Ptk_1Dc2iPY)
482
+ ```
483
+
484
+ ```markdown
485
+ ![](//www.youtube.com/watch?v=Ptk_1Dc2iPY?width=800&height=500)
486
+ ```
487
+
488
+ #### Vimeo Usage
489
+
490
+ ```markdown
491
+ ![](https://vimeo.com/263856289)
492
+ ```
493
+
494
+ ```markdown
495
+ ![](https://vimeo.com/263856289?width=500&height=320)
496
+ ```
497
+
498
+ #### DailyMotion Usage
499
+
500
+ ```markdown
501
+ ![](https://www.dailymotion.com/video/x7tfyq3)
502
+ ```
503
+
504
+ ```markdown
505
+ ![](https://dai.ly/x7tgcev?width=100%&height=400)
506
+ ```
507
+
508
+ ### 5. Hybrid HTML with Markdown
509
+
510
+ 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.
511
+
512
+ It's easy to write markdown inside HTML:
513
+
514
+ ```html
515
+ <script type="text/markdown">
516
+ # Hybrid HTML with Markdown is a not bad choice ^\_^
517
+
518
+ ## Table Usage
519
+
520
+ | : Fruits \|\| Food : |||
521
+ | :--------- | :-------- | :-------- |
522
+ | Apple | : Apple :| Apple \
523
+ | Banana | Banana | Banana \
524
+ | Orange | Orange | Orange |
525
+ | : Rowspan is 4 : || How's it? |
526
+ |^^ A. Peach || 1. Fine :|
527
+ |^^ B. Orange ||^^ 2. Bad |
528
+ |^^ C. Banana || It's OK! |
529
+
530
+ ## PlantUML Usage
531
+
532
+ @startuml
533
+ Bob -> Alice : hello
534
+ @enduml
535
+
536
+ ## Video Usage
537
+
538
+ ![](https://www.youtube.com/watch?v=Ptk_1Dc2iPY)
539
+ </script>
540
+ ```
541
+
542
+ ### 6. Markdown Polyfill
543
+
544
+ It allows us to polyfill features for extending markdown syntax.
545
+
546
+ **For now, these polyfill features are provided:**
547
+
548
+ - Escape ordered list
549
+
550
+ #### Escape Ordered List
551
+
552
+ A backslash at begin to escape the ordered list.
553
+
554
+ ```markdown
555
+ Normal:
556
+
557
+ 1. List item Apple.
558
+ 3. List item Banana.
559
+ 10. List item Cafe.
560
+
561
+ Escaped:
562
+
563
+ \1. List item Apple.
564
+ \3. List item Banana.
565
+ \10. List item Cafe.
566
+ ```
567
+
568
+ Code above would be parsed as:
569
+
570
+ ```markdown
571
+ Normal:
572
+
573
+ 1. List item Apple.
574
+ 2. List item Banana.
575
+ 3. List item Cafe.
576
+
577
+ Escaped:
578
+
579
+ 1. List item Apple.
580
+ 3. List item Banana.
581
+ 10. List item Cafe.
365
582
  ```
366
- ````
367
583
 
368
584
  ## Credits
369
585
 
@@ -378,4 +594,5 @@ Issues and Pull Requests are greatly appreciated. If you've never contributed to
378
594
  You can start by [opening an issue](https://github.com/jeffreytse/jekyll-spaceship/issues/new) describing the problem that you're looking to resolve and we'll go from there.
379
595
 
380
596
  ## License
597
+
381
598
  This software is licensed under the [MIT license](https://opensource.org/licenses/mit-license.php) © JeffreyTse.
@@ -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, etc."
12
+ spec.summary = "A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, youtube, etc."
13
13
  spec.homepage = "https://github.com/jeffreytse/jekyll-spaceship"
14
14
  spec.license = "MIT"
15
15
 
@@ -27,7 +27,7 @@ module Jekyll::Spaceship
27
27
  end
28
28
 
29
29
  def has_mathjax_expression?(doc)
30
- doc.css('p').each do |node|
30
+ doc.css('*').each do |node|
31
31
  if node.content.match(/\$.+\$/)
32
32
  return true
33
33
  end
@@ -6,6 +6,26 @@ require "nokogiri"
6
6
  module Jekyll::Spaceship
7
7
  class TableProcessor < Processor
8
8
  def on_handle_markdown(content)
9
+ # pre-handle reference-style links
10
+ references = {}
11
+ content.scan(/(\[(.*)\]:\s*(.*))/) do |match_data|
12
+ ref_name = match_data[1]
13
+ ref_value = match_data[2]
14
+ references[ref_name] = ref_value
15
+ end
16
+ if references.size > 0
17
+ content.scan(/.*(?<!\\)\|.*/) do |result|
18
+ references.each do |key, val|
19
+ replace = result.gsub(/\[(.*)\]\s*\[#{key}\]/, "[\1](#{val})")
20
+ next if result == replace
21
+ content = content.gsub(result, replace)
22
+ end
23
+ end
24
+ end
25
+
26
+ # pre-handle row-span
27
+ content = content.gsub(/(?<!\\)(\|.*\\\s*)\|\s*\n/, "\\1\n")
28
+
9
29
  # escape | and :
10
30
  content = content.gsub(/\|(?=\|)/, '\\|')
11
31
  .gsub(/\\:(?=.*?(?<!\\)\|)/, '\\\\\\\\:')
@@ -15,13 +35,10 @@ module Jekyll::Spaceship
15
35
  content.scan(/.*(?<!\\)\|.*/) do |result|
16
36
  replace = result.gsub(
17
37
  /(?<!(?<!\\)\\)(\*|\$|\[|\(|\"|_)/,
18
- '\\\\\\\\\1'
19
- )
20
- if result != replace
21
- content = content.gsub(result, replace)
22
- end
38
+ '\\\\\\\\\1')
39
+ next if result == replace
40
+ content = content.gsub(result, replace)
23
41
  end
24
-
25
42
  content
26
43
  end
27
44
 
@@ -123,9 +140,9 @@ module Jekyll::Spaceship
123
140
  # handle multi-rows
124
141
  return if cell != cells.last
125
142
 
126
- match = cell.content.match(/\\$/)
143
+ match = cell.content.match(/(?<!\\)\\\s*$/)
127
144
  if match
128
- cell.content = cell.content.gsub(/\\$/, '')
145
+ cell.content = cell.content.gsub(/(?<!\\)\\\s*$/, '')
129
146
  if not scope_table.multi_row_start
130
147
  scope_table.multi_row_cells = cells
131
148
  scope_table.multi_row_start = true
@@ -161,8 +178,8 @@ module Jekyll::Spaceship
161
178
 
162
179
  # handle rowspan
163
180
  span_cell = scope_table.span_row_cells[scope_row.col_index]
164
- if span_cell and cell.content.match(/^\^{2}/)
165
- cell.content = cell.content.gsub(/^\^{2}/, '')
181
+ if span_cell and cell.content.match(/^\s*\^{2}/)
182
+ cell.content = cell.content.gsub(/^\s*\^{2}/, '')
166
183
  span_cell.content += " \n#{cell.content}"
167
184
  rowspan = span_cell.get_attribute('rowspan') || 1
168
185
  rowspan = rowspan.to_i + 1
@@ -180,12 +197,12 @@ module Jekyll::Spaceship
180
197
 
181
198
  # pre-handle text align
182
199
  align = 0
183
- if cell.content.match(/^:(?!:)/)
184
- cell.content = cell.content.gsub(/^:/, '')
200
+ if cell.content.match(/^\s*:(?!:)/)
201
+ cell.content = cell.content.gsub(/^\s*:/, '')
185
202
  align += 1
186
203
  end
187
- if cell.content.match(/(?<!\\):$/)
188
- cell.content = cell.content.gsub(/:$/, '')
204
+ if cell.content.match(/(?<!\\):\s*$/)
205
+ cell.content = cell.content.gsub(/:\s*$/, '')
189
206
  align += 2
190
207
  end
191
208
 
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll::Spaceship
4
+ class VideoProcessor < Processor
5
+ def on_handle_markdown(content)
6
+ content = handle_youtube(content)
7
+ content = handle_vimeo(content)
8
+ content = handle_dailymotion(content)
9
+ end
10
+
11
+ # Examples:
12
+ # ![youtube](https://www.youtube.com/watch?v=XA2WjJbmmoM "title")
13
+ # ![youtube](http://www.youtube.com/embed/w-m_yZCLF5Q)
14
+ # ![youtube](//youtu.be/mEP3YXaSww8?height=100%&width=400)
15
+ def handle_youtube(content)
16
+ handle_video(content, {
17
+ host: '(https?:)?\\/\\/.*youtu.*',
18
+ id: '(?<=\\?v\\=|embed\\/|\\.be\\/)([a-zA-Z0-9\\_\\-]+)',
19
+ iframe_url: "https://www.youtube.com/embed/"
20
+ })
21
+ end
22
+
23
+ # Examples:
24
+ # ![vimeo](https://vimeo.com/263856289)
25
+ # ![vimeo](https://vimeo.com/263856289?height=100%&width=400)
26
+ def handle_vimeo(content)
27
+ handle_video(content, {
28
+ host: '(https?:)?\\/\\/vimeo\\.com\\/',
29
+ id: '([0-9]+)',
30
+ iframe_url: "https://player.vimeo.com/video/",
31
+ width: 600,
32
+ height: 350
33
+ })
34
+ end
35
+
36
+ # Examples:
37
+ # ![dailymotion](https://www.dailymotion.com/video/x7tgcev)
38
+ # ![dailymotion](https://dai.ly/x7tgcev?height=100%&width=400)
39
+ def handle_dailymotion(content)
40
+ handle_video(content, {
41
+ host: '(https?:)?\\/\\/.*dai.?ly.*',
42
+ id: '(?<=video\\/|\\/)([a-zA-Z0-9\\_\\-]+)',
43
+ iframe_url: "https://www.dailymotion.com/embed/video/"
44
+ })
45
+ end
46
+
47
+ def handle_video(content, data)
48
+ host = data[:host]
49
+ return content if content.sub(/#{host}/, '').nil?
50
+
51
+ iframe_url = data[:iframe_url]
52
+ id = data[:id]
53
+ url = "(#{host}#{id}\\S*)"
54
+ title = '("(.*)".*){0,1}'
55
+
56
+ # pre-handle reference-style links
57
+ regex = /(\[(.*)\]:\s*(#{url}\s*#{title}))/
58
+ content.scan regex do |match_data|
59
+ match = match_data[0]
60
+ ref_name = match_data[1]
61
+ ref_value = match_data[2]
62
+ content = content.gsub(match, '')
63
+ .gsub(/\!\[(.*)\]\s*\[#{ref_name}\]/,
64
+ "![\1](#{ref_value})")
65
+ end
66
+
67
+ # handle inline-style links
68
+ regex = /(\!\[(.*)\]\(.*#{url}\s*#{title}\))/
69
+ content.scan regex do |match_data|
70
+ url = match_data[2]
71
+ id = match_data[4]
72
+ title = match_data[6]
73
+ width = url.match(/(?<=width=)(\S*?)(?=&|$)/)
74
+ height = url.match(/(?<=height=)(\S*?)(?=&|$)/)
75
+
76
+ data[:width] = 600 if data[:width].nil?
77
+ data[:height] = 400 if data[:height].nil?
78
+ width = data[:width] if width.nil?
79
+ height = data[:height] if height.nil?
80
+
81
+ url = "#{iframe_url}#{id}"
82
+ html = "<iframe \
83
+ src=\"#{url}\" \
84
+ title=\"#{title}\" \
85
+ width=\"#{width}\" \
86
+ height=\"#{height}\" \
87
+ frameborder=\"0\" \
88
+ allowfullscreen=\"\">\
89
+ </iframe>"
90
+
91
+ content = content.gsub(match_data[0], html)
92
+ self.handled = true
93
+ end
94
+ content
95
+ end
96
+ end
97
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Spaceship
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
@@ -10,4 +10,5 @@ module Jekyll::Spaceship
10
10
  Register.use 'mathjax-processor'
11
11
  Register.use 'plantuml-processor'
12
12
  Register.use 'polyfill-processor'
13
+ Register.use 'video-processor'
13
14
  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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeffreytse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-24 00:00:00.000000000 Z
11
+ date: 2020-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -100,6 +100,7 @@ files:
100
100
  - lib/jekyll-spaceship/processors/plantuml-processor.rb
101
101
  - lib/jekyll-spaceship/processors/polyfill-processor.rb
102
102
  - lib/jekyll-spaceship/processors/table-processor.rb
103
+ - lib/jekyll-spaceship/processors/video-processor.rb
103
104
  - lib/jekyll-spaceship/utils/plantuml/plantuml.jar
104
105
  - lib/jekyll-spaceship/version.rb
105
106
  homepage: https://github.com/jeffreytse/jekyll-spaceship
@@ -125,5 +126,5 @@ rubygems_version: 3.0.6
125
126
  signing_key:
126
127
  specification_version: 4
127
128
  summary: A Jekyll plugin to provide powerful supports for table, mathjax, plantuml,
128
- etc.
129
+ youtube, etc.
129
130
  test_files: []