jekyll-gfm-admonitions 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +0 -30
- data/lib/jekyll-gfm-admonitions.rb +52 -37
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e430262ea2a0d62b88656fc9d61a244f4840e6ae0a67699440f64c129671c98
|
4
|
+
data.tar.gz: 580f689cdf7e6072108a039164198ef17dd32e160879d7fdfc0ffe7dcce24ac6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27109d0a6495fbec17fd52b46872362a3fa056832e5faa16a8837b77c4f4596c0177a08c9f53e020312370046530d9afd7f80bdaa7315245c30b9235ffd59bbc
|
7
|
+
data.tar.gz: eae65a1558f810cdd52d8af2b5cc91d8acfc210ae6cf5380f9047766baa94aff5961c20084793c486cb612100b7bd4aa621e3024adfe48878404b737b1d5f115
|
data/README.md
CHANGED
@@ -61,16 +61,9 @@ group :jekyll_plugins do
|
|
61
61
|
|
62
62
|
# ... Add this line:
|
63
63
|
gem "jekyll-gfm-admonitions"
|
64
|
-
gem "jekyll-optional-front-matter"
|
65
64
|
end
|
66
65
|
```
|
67
66
|
|
68
|
-
> [!TIP]
|
69
|
-
>
|
70
|
-
> By installing `jekyll-optional-front-matter` alongside this package, you won't need to
|
71
|
-
> add ([visible](https://github.com/github/markup/issues/994)) frontmatter headers to each
|
72
|
-
> of your files.
|
73
|
-
|
74
67
|
Then run:
|
75
68
|
|
76
69
|
```bash
|
@@ -84,7 +77,6 @@ Next, you need to enable the plugin in your Jekyll configuration file (`_config.
|
|
84
77
|
```yaml
|
85
78
|
plugins:
|
86
79
|
- jekyll-gfm-admonitions
|
87
|
-
- jekyll-optional-front-matter
|
88
80
|
```
|
89
81
|
|
90
82
|
Then, during `build`/`serve`, you should see logs similar to:
|
@@ -158,28 +150,6 @@ end
|
|
158
150
|
gem 'jekyll-remote-theme'
|
159
151
|
```
|
160
152
|
|
161
|
-
### Add [front matter](https://jekyllrb.com/docs/front-matter/)
|
162
|
-
|
163
|
-
This step is optional if you've added `jekyll-front-matter`. If you do not, any file
|
164
|
-
without a front matter header will be ignored by Jekyll, and only partially included by
|
165
|
-
the GitHub Pages plugin.
|
166
|
-
|
167
|
-
Make sure that all your `.md` files begin with a valid front matter header:
|
168
|
-
|
169
|
-
```markdown
|
170
|
-
---
|
171
|
-
---
|
172
|
-
|
173
|
-
Your markdown files should start like this.
|
174
|
-
```
|
175
|
-
|
176
|
-
> [!IMPORTANT]
|
177
|
-
>
|
178
|
-
> Your root `README.md` front matter should contain the following `permalink` attribute:
|
179
|
-
> ```yaml
|
180
|
-
> permalink: /index.html
|
181
|
-
> ```
|
182
|
-
|
183
153
|
## License
|
184
154
|
|
185
155
|
This project is licensed under the MIT License. See the [LICENSE.txt](LICENSE.txt) file
|
@@ -23,60 +23,72 @@ 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
|
-
|
26
|
+
priority :lowest
|
27
|
+
@admonition_pages = []
|
27
28
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
29
|
+
def generate(site)
|
30
|
+
init_converter(site)
|
31
|
+
process_posts(site)
|
32
|
+
process_pages(site)
|
33
|
+
Jekyll.logger.info 'GFMA:', 'Converted adminitions in' \
|
34
|
+
" #{self.class.admonition_pages.length} file(s)."
|
31
35
|
end
|
32
36
|
|
33
|
-
def
|
37
|
+
def init_converter(site)
|
34
38
|
@markdown = site.converters.find { |c| c.is_a?(Jekyll::Converters::Markdown) }
|
35
|
-
|
36
|
-
raise "Markdown converter not found. Please ensure that you have a markdown converter configured in your Jekyll site."
|
37
|
-
end
|
39
|
+
return if @markdown
|
38
40
|
|
39
|
-
|
41
|
+
raise 'Markdown converter not found. Please ensure that you have a markdown' \
|
42
|
+
' converter configured in your Jekyll site.'
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_posts(site)
|
40
46
|
site.posts.docs.each do |doc|
|
41
47
|
Jekyll.logger.debug 'GFMA:', "Processing post '#{doc.path}' (#{doc.content.length} characters)."
|
42
|
-
|
48
|
+
process_doc(doc)
|
43
49
|
end
|
50
|
+
end
|
44
51
|
|
45
|
-
|
52
|
+
def process_pages(site)
|
46
53
|
site.pages.each do |page|
|
47
|
-
# Patch the root README for GitHub Pages builds
|
48
|
-
if page.path == 'README.md' && page.dir == '/'
|
49
|
-
Jekyll.logger.info 'GFMA:', "Patched /README.html to /index.html"
|
50
|
-
page.instance_variable_set(:@url, '/index.html')
|
51
|
-
end
|
52
54
|
Jekyll.logger.debug 'GFMA:', "Processing page '#{page.path}' (#{page.content.length} characters)."
|
53
|
-
|
55
|
+
process_doc_content(page)
|
54
56
|
end
|
55
|
-
|
56
|
-
Jekyll.logger.info 'GFMA:', "Converted adminitions in #{@converted} file(s)."
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
59
|
+
def process_doc_content(doc)
|
60
60
|
original_content = doc.content.dup
|
61
|
-
|
61
|
+
process_doc(doc)
|
62
62
|
|
63
63
|
return unless doc.content != original_content
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
# Store a reference to all the pages we modified, to inject the CSS post render
|
66
|
+
# (otherwise GitHub Pages sanitizes the CSS into plaintext)
|
67
|
+
self.class.admonition_pages << doc
|
67
68
|
end
|
68
69
|
|
69
|
-
|
70
|
-
|
70
|
+
class << self
|
71
|
+
attr_reader :admonition_pages
|
71
72
|
end
|
72
73
|
|
73
|
-
def
|
74
|
+
def process_doc(doc)
|
74
75
|
code_blocks = []
|
75
|
-
|
76
|
+
# Temporarily replace code blocks by a tag, so that we don't process any admonitions
|
77
|
+
# inside of code blocks.
|
78
|
+
doc.content.gsub!(/(?:^|\n)(?<!>)\s*```.*?```/m) do |match|
|
76
79
|
code_blocks << match
|
77
80
|
"```{{CODE_BLOCK_#{code_blocks.length - 1}}}```"
|
78
81
|
end
|
79
82
|
|
83
|
+
convert_admonitions(doc)
|
84
|
+
|
85
|
+
# Put the code blocks back in place
|
86
|
+
doc.content.gsub!(/```\{\{CODE_BLOCK_(\d+)}}```/) do
|
87
|
+
code_blocks[::Regexp.last_match(1).to_i]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def convert_admonitions(doc)
|
80
92
|
doc.content.gsub!(/>\s*\[!(IMPORTANT|NOTE|WARNING|TIP|CAUTION)\]\s*\n((?:>.*\n?)*)/) do
|
81
93
|
type = ::Regexp.last_match(1).downcase
|
82
94
|
title = type.capitalize
|
@@ -84,26 +96,29 @@ module JekyllGFMAdmonitions
|
|
84
96
|
icon = Octicons::Octicon.new(ADMONITION_ICONS[type]).to_svg
|
85
97
|
Jekyll.logger.debug 'GFMA:', "Converting #{type} admonition."
|
86
98
|
|
87
|
-
|
99
|
+
admonition_html(type, title, text, icon)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def admonition_html(type, title, text, icon)
|
104
|
+
"<div class='markdown-alert markdown-alert-#{type}'>
|
88
105
|
<p class='markdown-alert-title'>#{icon} #{title}</p>
|
89
106
|
<p>#{@markdown.convert(text)}</p>
|
90
107
|
</div>\n\n"
|
91
|
-
end
|
92
|
-
|
93
|
-
doc.content.gsub!(/```\{\{CODE_BLOCK_(\d+)}}```/) do
|
94
|
-
"```#{code_blocks[$1.to_i]}```"
|
95
|
-
end
|
96
108
|
end
|
97
109
|
end
|
98
110
|
|
99
|
-
|
100
|
-
|
111
|
+
# Insert the minified CSS before the closing head tag of all pages we put admonitions on
|
112
|
+
Jekyll::Hooks.register :site, :post_render do
|
113
|
+
Jekyll.logger.info 'GFMA:', "Inserting admonition CSS in #{GFMAdmonitionConverter.admonition_pages.length} page(s)."
|
101
114
|
|
102
|
-
|
115
|
+
GFMAdmonitionConverter.admonition_pages.each do |page|
|
103
116
|
Jekyll.logger.debug 'GFMA:', "Appending admonition style to '#{page.path}'."
|
104
117
|
css = File.read(File.expand_path('../assets/admonitions.css', __dir__))
|
105
118
|
|
106
|
-
page.output
|
119
|
+
page.output.gsub!(%r{<head>(.*?)</head>}m) do |match|
|
120
|
+
"#{match[0..-7]}<style>#{CSSminify.compress(css)}</style>#{match[-7..]}"
|
121
|
+
end
|
107
122
|
end
|
108
123
|
end
|
109
124
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-gfm-admonitions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robin De Schepper
|
@@ -11,33 +11,33 @@ cert_chain: []
|
|
11
11
|
date: 2024-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: cssminify
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: jekyll
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '3.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: octicons
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|