jekyll-gfm-admonitions 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -30
  3. data/lib/jekyll-gfm-admonitions.rb +42 -38
  4. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75cc2a5cd4eaf0017bf2a47ca438f1be25b4a20212faf13e3e40f048ec263cb4
4
- data.tar.gz: 274fe45c83097424b627c66d721c68760298f6e2413b361d0f87cb0d62cc6462
3
+ metadata.gz: 6e430262ea2a0d62b88656fc9d61a244f4840e6ae0a67699440f64c129671c98
4
+ data.tar.gz: 580f689cdf7e6072108a039164198ef17dd32e160879d7fdfc0ffe7dcce24ac6
5
5
  SHA512:
6
- metadata.gz: 10967a4046bd913e5611421e3fb5d2d2253fde61161b588af2c294ad79340e53143a83390590b1a7252c616df73f3e3ba7991e1f4646731d045af7960c0592bd
7
- data.tar.gz: 50fc8c02dc6b000e4824bd60da24b1f324289b83784d8e6e870879eaeb65d887916e142bbb5daaf232d15617483046ac4009821e163bb3f76a83303dd7d04840
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
@@ -24,56 +24,54 @@ module JekyllGFMAdmonitions
24
24
  class GFMAdmonitionConverter < Jekyll::Generator
25
25
  safe true
26
26
  priority :lowest
27
- @@admonition_pages = []
27
+ @admonition_pages = []
28
28
 
29
- def initialize(*args)
30
- super(*args)
31
- @converted = 0
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)."
32
35
  end
33
36
 
34
- def generate(site)
37
+ def init_converter(site)
35
38
  @markdown = site.converters.find { |c| c.is_a?(Jekyll::Converters::Markdown) }
36
- unless @markdown
37
- raise "Markdown converter not found. Please ensure that you have a markdown converter configured in your Jekyll site."
38
- end
39
+ return if @markdown
39
40
 
40
- # Process admonitions in posts
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)
41
46
  site.posts.docs.each do |doc|
42
47
  Jekyll.logger.debug 'GFMA:', "Processing post '#{doc.path}' (#{doc.content.length} characters)."
43
- process(doc)
48
+ process_doc(doc)
44
49
  end
50
+ end
45
51
 
46
- # Process admonitions in pages
52
+ def process_pages(site)
47
53
  site.pages.each do |page|
48
- # Patch the root README for GitHub Pages builds
49
- if page.path == 'README.md' && page.dir == '/'
50
- Jekyll.logger.info 'GFMA:', "Patched /README.html to /index.html"
51
- page.instance_variable_set(:@url, '/index.html')
52
- end
53
-
54
54
  Jekyll.logger.debug 'GFMA:', "Processing page '#{page.path}' (#{page.content.length} characters)."
55
- process(page)
55
+ process_doc_content(page)
56
56
  end
57
-
58
- Jekyll.logger.info 'GFMA:', "Converted adminitions in #{@converted} file(s)."
59
57
  end
60
58
 
61
- def process(doc)
59
+ def process_doc_content(doc)
62
60
  original_content = doc.content.dup
63
- convert_admonitions(doc)
61
+ process_doc(doc)
64
62
 
65
63
  return unless doc.content != original_content
64
+
66
65
  # Store a reference to all the pages we modified, to inject the CSS post render
67
66
  # (otherwise GitHub Pages sanitizes the CSS into plaintext)
68
- @@admonition_pages << doc
69
- @converted += 1
67
+ self.class.admonition_pages << doc
70
68
  end
71
69
 
72
- def self.admonition_pages
73
- return @@admonition_pages
70
+ class << self
71
+ attr_reader :admonition_pages
74
72
  end
75
73
 
76
- def convert_admonitions(doc)
74
+ def process_doc(doc)
77
75
  code_blocks = []
78
76
  # Temporarily replace code blocks by a tag, so that we don't process any admonitions
79
77
  # inside of code blocks.
@@ -82,7 +80,15 @@ module JekyllGFMAdmonitions
82
80
  "```{{CODE_BLOCK_#{code_blocks.length - 1}}}```"
83
81
  end
84
82
 
85
- # Match the admonition syntax
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)
86
92
  doc.content.gsub!(/>\s*\[!(IMPORTANT|NOTE|WARNING|TIP|CAUTION)\]\s*\n((?:>.*\n?)*)/) do
87
93
  type = ::Regexp.last_match(1).downcase
88
94
  title = type.capitalize
@@ -90,17 +96,15 @@ module JekyllGFMAdmonitions
90
96
  icon = Octicons::Octicon.new(ADMONITION_ICONS[type]).to_svg
91
97
  Jekyll.logger.debug 'GFMA:', "Converting #{type} admonition."
92
98
 
93
- # Replace them by the GFM admonition HTML
94
- "<div class='markdown-alert markdown-alert-#{type}'>
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}'>
95
105
  <p class='markdown-alert-title'>#{icon} #{title}</p>
96
106
  <p>#{@markdown.convert(text)}</p>
97
107
  </div>\n\n"
98
- end
99
-
100
- # Put the code blocks back in place
101
- doc.content.gsub!(/```\{\{CODE_BLOCK_(\d+)}}```/) do
102
- code_blocks[$1.to_i]
103
- end
104
108
  end
105
109
  end
106
110
 
@@ -112,8 +116,8 @@ module JekyllGFMAdmonitions
112
116
  Jekyll.logger.debug 'GFMA:', "Appending admonition style to '#{page.path}'."
113
117
  css = File.read(File.expand_path('../assets/admonitions.css', __dir__))
114
118
 
115
- page.output.gsub!(/<head>(.*?)<\/head>/m) do |match|
116
- "#{match[0..-7]}<style>#{CSSminify.compress(css)}</style>#{match[-7..-1]}"
119
+ page.output.gsub!(%r{<head>(.*?)</head>}m) do |match|
120
+ "#{match[0..-7]}<style>#{CSSminify.compress(css)}</style>#{match[-7..]}"
117
121
  end
118
122
  end
119
123
  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.1
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: jekyll
14
+ name: cssminify
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
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: '3.0'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: cssminify
28
+ name: jekyll
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
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: '1.0'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: octicons
43
43
  requirement: !ruby/object:Gem::Requirement