jekyll-gfm-admonitions 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-gfm-admonitions.rb +18 -7
- 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: 75cc2a5cd4eaf0017bf2a47ca438f1be25b4a20212faf13e3e40f048ec263cb4
|
4
|
+
data.tar.gz: 274fe45c83097424b627c66d721c68760298f6e2413b361d0f87cb0d62cc6462
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10967a4046bd913e5611421e3fb5d2d2253fde61161b588af2c294ad79340e53143a83390590b1a7252c616df73f3e3ba7991e1f4646731d045af7960c0592bd
|
7
|
+
data.tar.gz: 50fc8c02dc6b000e4824bd60da24b1f324289b83784d8e6e870879eaeb65d887916e142bbb5daaf232d15617483046ac4009821e163bb3f76a83303dd7d04840
|
@@ -23,6 +23,7 @@ module JekyllGFMAdmonitions
|
|
23
23
|
# syntax with HTML markup that includes appropriate iconography and CSS styling.
|
24
24
|
class GFMAdmonitionConverter < Jekyll::Generator
|
25
25
|
safe true
|
26
|
+
priority :lowest
|
26
27
|
@@admonition_pages = []
|
27
28
|
|
28
29
|
def initialize(*args)
|
@@ -49,6 +50,7 @@ module JekyllGFMAdmonitions
|
|
49
50
|
Jekyll.logger.info 'GFMA:', "Patched /README.html to /index.html"
|
50
51
|
page.instance_variable_set(:@url, '/index.html')
|
51
52
|
end
|
53
|
+
|
52
54
|
Jekyll.logger.debug 'GFMA:', "Processing page '#{page.path}' (#{page.content.length} characters)."
|
53
55
|
process(page)
|
54
56
|
end
|
@@ -61,7 +63,8 @@ module JekyllGFMAdmonitions
|
|
61
63
|
convert_admonitions(doc)
|
62
64
|
|
63
65
|
return unless doc.content != original_content
|
64
|
-
|
66
|
+
# Store a reference to all the pages we modified, to inject the CSS post render
|
67
|
+
# (otherwise GitHub Pages sanitizes the CSS into plaintext)
|
65
68
|
@@admonition_pages << doc
|
66
69
|
@converted += 1
|
67
70
|
end
|
@@ -72,11 +75,14 @@ module JekyllGFMAdmonitions
|
|
72
75
|
|
73
76
|
def convert_admonitions(doc)
|
74
77
|
code_blocks = []
|
75
|
-
|
78
|
+
# Temporarily replace code blocks by a tag, so that we don't process any admonitions
|
79
|
+
# inside of code blocks.
|
80
|
+
doc.content.gsub!(/(?:^|\n)(?<!>)\s*```.*?```/m) do |match|
|
76
81
|
code_blocks << match
|
77
82
|
"```{{CODE_BLOCK_#{code_blocks.length - 1}}}```"
|
78
83
|
end
|
79
84
|
|
85
|
+
# Match the admonition syntax
|
80
86
|
doc.content.gsub!(/>\s*\[!(IMPORTANT|NOTE|WARNING|TIP|CAUTION)\]\s*\n((?:>.*\n?)*)/) do
|
81
87
|
type = ::Regexp.last_match(1).downcase
|
82
88
|
title = type.capitalize
|
@@ -84,26 +90,31 @@ module JekyllGFMAdmonitions
|
|
84
90
|
icon = Octicons::Octicon.new(ADMONITION_ICONS[type]).to_svg
|
85
91
|
Jekyll.logger.debug 'GFMA:', "Converting #{type} admonition."
|
86
92
|
|
93
|
+
# Replace them by the GFM admonition HTML
|
87
94
|
"<div class='markdown-alert markdown-alert-#{type}'>
|
88
95
|
<p class='markdown-alert-title'>#{icon} #{title}</p>
|
89
96
|
<p>#{@markdown.convert(text)}</p>
|
90
97
|
</div>\n\n"
|
91
98
|
end
|
92
99
|
|
100
|
+
# Put the code blocks back in place
|
93
101
|
doc.content.gsub!(/```\{\{CODE_BLOCK_(\d+)}}```/) do
|
94
|
-
|
102
|
+
code_blocks[$1.to_i]
|
95
103
|
end
|
96
104
|
end
|
97
105
|
end
|
98
106
|
|
99
|
-
|
100
|
-
|
107
|
+
# Insert the minified CSS before the closing head tag of all pages we put admonitions on
|
108
|
+
Jekyll::Hooks.register :site, :post_render do
|
109
|
+
Jekyll.logger.info 'GFMA:', "Inserting admonition CSS in #{GFMAdmonitionConverter.admonition_pages.length} page(s)."
|
101
110
|
|
102
|
-
|
111
|
+
GFMAdmonitionConverter.admonition_pages.each do |page|
|
103
112
|
Jekyll.logger.debug 'GFMA:', "Appending admonition style to '#{page.path}'."
|
104
113
|
css = File.read(File.expand_path('../assets/admonitions.css', __dir__))
|
105
114
|
|
106
|
-
page.output
|
115
|
+
page.output.gsub!(/<head>(.*?)<\/head>/m) do |match|
|
116
|
+
"#{match[0..-7]}<style>#{CSSminify.compress(css)}</style>#{match[-7..-1]}"
|
117
|
+
end
|
107
118
|
end
|
108
119
|
end
|
109
120
|
end
|