jekyll-gfm-admonitions 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/admonitions.css +1 -1
- data/lib/jekyll-gfm-admonitions.rb +25 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f4d88903b4f39d857f537e963c51676d129aa64a1b01b1347384d450f1c715b
|
4
|
+
data.tar.gz: 27f1bb25919a5de02325aa0000fff47840ef0a96fdcccde1f55527cf4b1d2d7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c6a301cf15df7bd44ed11138059799d73c494a092649c0b92bfe9c189c026b8642de86d52d1fc90151b0063f446f8fb56ec4ac625f2e59018a445400459377a
|
7
|
+
data.tar.gz: 90f9cd3ead495506ddc433b2b593286ec8ba1f6e8d3477d992b779b3f2d70d54f4e3b3f55e67a7099bb7ab73b141a84a276661d179e6c395de9e89024bdbc362
|
data/assets/admonitions.css
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'octicons'
|
4
4
|
require 'cssminify'
|
5
|
+
require 'liquid/template'
|
5
6
|
|
6
7
|
ADMONITION_ICONS = {
|
7
8
|
'important' => 'report',
|
@@ -22,6 +23,7 @@ module JekyllGFMAdmonitions
|
|
22
23
|
# syntax with HTML markup that includes appropriate iconography and CSS styling.
|
23
24
|
class GFMAdmonitionConverter < Jekyll::Generator
|
24
25
|
safe true
|
26
|
+
@@admonition_pages = []
|
25
27
|
|
26
28
|
def initialize(*args)
|
27
29
|
super(*args)
|
@@ -29,13 +31,21 @@ module JekyllGFMAdmonitions
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def generate(site)
|
34
|
+
@markdown = site.converters.find { |c| c.is_a?(Jekyll::Converters::Markdown) }
|
35
|
+
unless @markdown
|
36
|
+
raise "Markdown converter not found. Please ensure that you have a markdown converter configured in your Jekyll site."
|
37
|
+
end
|
38
|
+
|
32
39
|
# Process admonitions in posts
|
33
40
|
site.posts.docs.each do |doc|
|
41
|
+
Jekyll.logger.debug 'GFMA:', "Processing post '#{doc.path}' (#{doc.content.length} characters)."
|
34
42
|
process(doc)
|
35
43
|
end
|
36
44
|
|
37
45
|
# Process admonitions in pages
|
38
46
|
site.pages.each do |page|
|
47
|
+
Jekyll.logger.debug 'GFMA:', "Processing page '#{page.path}' (#{page.content.length} characters)."
|
48
|
+
Jekyll.logger.debug 'GFMA:', "#{page.content.inspect}"
|
39
49
|
process(page)
|
40
50
|
end
|
41
51
|
|
@@ -48,27 +58,38 @@ module JekyllGFMAdmonitions
|
|
48
58
|
|
49
59
|
return unless doc.content != original_content
|
50
60
|
|
51
|
-
|
61
|
+
@@admonition_pages << doc
|
52
62
|
@converted += 1
|
53
63
|
end
|
54
64
|
|
65
|
+
def self.admonition_pages
|
66
|
+
return @@admonition_pages
|
67
|
+
end
|
68
|
+
|
55
69
|
def convert_admonitions(doc)
|
56
70
|
doc.content.gsub!(/>\s*\[!(IMPORTANT|NOTE|WARNING|TIP|CAUTION)\]\s*\n((?:>.*\n?)*)/) do
|
57
71
|
type = ::Regexp.last_match(1).downcase
|
58
72
|
title = type.capitalize
|
59
73
|
text = ::Regexp.last_match(2).gsub(/^>\s*/, '').strip
|
60
74
|
icon = Octicons::Octicon.new(ADMONITION_ICONS[type]).to_svg
|
75
|
+
Jekyll.logger.debug 'GFMA:', "Converting #{type} admonition."
|
61
76
|
|
62
77
|
"<div class='markdown-alert markdown-alert-#{type}'>
|
63
78
|
<p class='markdown-alert-title'>#{icon} #{title}</p>
|
64
|
-
<p>#{text}</p>
|
79
|
+
<p>#{@markdown.convert(text)}</p>
|
65
80
|
</div>"
|
66
81
|
end
|
67
82
|
end
|
83
|
+
end
|
84
|
+
|
85
|
+
Jekyll::Hooks.register :site, :post_render do |site|
|
86
|
+
Jekyll.logger.info 'GFMA:', "Injecting admonition CSS in #{GFMAdmonitionConverter.admonition_pages.length} page(s)."
|
68
87
|
|
69
|
-
|
88
|
+
for page in GFMAdmonitionConverter.admonition_pages do
|
89
|
+
Jekyll.logger.debug 'GFMA:', "Appending admonition style to '#{page.path}'."
|
70
90
|
css = File.read(File.expand_path('../assets/admonitions.css', __dir__))
|
71
|
-
|
91
|
+
|
92
|
+
page.output += "<style>#{CSSminify.compress(css)}</style>"
|
72
93
|
end
|
73
94
|
end
|
74
95
|
end
|