jekyll-gfm-admonitions 0.2.1 → 1.0.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +100 -12
  3. data/lib/jekyll-gfm-admonitions.rb +31 -6
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bd3b14863c909fa009e741f378bff65b4727794fce307818a742e50859d233e
4
- data.tar.gz: bcbe98766111c4a71e8f98f1ba8fe00d9c036754262d9e6bc227a3dc54a60c59
3
+ metadata.gz: 75cc2a5cd4eaf0017bf2a47ca438f1be25b4a20212faf13e3e40f048ec263cb4
4
+ data.tar.gz: 274fe45c83097424b627c66d721c68760298f6e2413b361d0f87cb0d62cc6462
5
5
  SHA512:
6
- metadata.gz: 57df6efea88902eefe6de29525a290de68cb78165c9924d7d95f2f583c5812d9a676eb81570fa2649ec6201b04ac2eefbfaf9bb36e298548bb6de160555502bf
7
- data.tar.gz: d6f84ec3048005512cb32cde7647bfc0c02ab500a1b2bd8a74605e2a6053c66384829ac4a60b5b1b9cfc777020aab048492b7203eff770480e15f96d1a676af0
6
+ metadata.gz: 10967a4046bd913e5611421e3fb5d2d2253fde61161b588af2c294ad79340e53143a83390590b1a7252c616df73f3e3ba7991e1f4646731d045af7960c0592bd
7
+ data.tar.gz: 50fc8c02dc6b000e4824bd60da24b1f324289b83784d8e6e870879eaeb65d887916e142bbb5daaf232d15617483046ac4009821e163bb3f76a83303dd7d04840
data/README.md CHANGED
@@ -20,35 +20,35 @@ To use admonitions in your markdown files, simply add the following syntax:
20
20
 
21
21
  ```markdown
22
22
  > [!IMPORTANT]
23
- > This is an important message.
23
+ > This is an **important** message.
24
24
 
25
25
  > [!NOTE]
26
- > This is a note.
26
+ > This is a **note**.
27
27
 
28
28
  > [!TIP]
29
- > This is a helpful tip.
29
+ > This is a **helpful** tip.
30
30
 
31
31
  > [!WARNING]
32
- > This is a warning.
32
+ > This is a **warning**.
33
33
 
34
34
  > [!CAUTION]
35
- > This is a caution message.
35
+ > This is a **caution** message.
36
36
  ```
37
37
 
38
38
  > [!IMPORTANT]
39
- > This is an important message.
39
+ > This is an **important** message.
40
40
 
41
41
  > [!NOTE]
42
- > This is a note.
42
+ > This is a **note**.
43
43
 
44
44
  > [!TIP]
45
- > This is a helpful tip.
45
+ > This is a **helpful** tip.
46
46
 
47
47
  > [!WARNING]
48
- > This is a warning.
48
+ > This is a **warning**.
49
49
 
50
50
  > [!CAUTION]
51
- > This is a caution message.
51
+ > This is a **caution** message.
52
52
 
53
53
  ## Installation
54
54
 
@@ -61,9 +61,16 @@ group :jekyll_plugins do
61
61
 
62
62
  # ... Add this line:
63
63
  gem "jekyll-gfm-admonitions"
64
+ gem "jekyll-optional-front-matter"
64
65
  end
65
66
  ```
66
67
 
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
+
67
74
  Then run:
68
75
 
69
76
  ```bash
@@ -77,14 +84,18 @@ Next, you need to enable the plugin in your Jekyll configuration file (`_config.
77
84
  ```yaml
78
85
  plugins:
79
86
  - jekyll-gfm-admonitions
87
+ - jekyll-optional-front-matter
80
88
  ```
81
89
 
82
- Then, during build/serve, you should see a log similar to:
90
+ Then, during `build`/`serve`, you should see logs similar to:
83
91
 
84
92
  ```
85
- GFMA: Converted adminitions in 1 file(s).
93
+ GFMA: Converted adminitions in 36 file(s).
94
+ GFMA: Injecting admonition CSS in 36 page(s).
86
95
  ```
87
96
 
97
+ More details are available by passing the `--verbose` flag to your `jekyll` command.
98
+
88
99
  ## When using GitHub Pages
89
100
 
90
101
  To enable custom plugins in your Jekyll build for GitHub Pages, you need to use GitHub
@@ -92,6 +103,83 @@ Actions (GHA) to build and deploy your Jekyll site. For detailed instructions on
92
103
  up GitHub Actions for your Jekyll project, please follow this link:
93
104
  [GitHub Actions Setup for Jekyll](https://jekyllrb.com/docs/continuous-integration/github-actions/).
94
105
 
106
+ After following the steps you will have to set up a minimal valid Jekyll project.
107
+
108
+ ### Add a `_config.yml`
109
+
110
+ ```yaml
111
+ # Site settings
112
+ title: Your Project Title
113
+ repository: your-username/your-repository
114
+ description: >-
115
+ A description of your project
116
+
117
+ markdown: GFM
118
+ plugins:
119
+ - jekyll-gfm-admonitions
120
+ - jekyll-optional-front-matter
121
+
122
+ exclude:
123
+ - "**/*.ts" # Exclude source code files!
124
+ - "**/*.js"
125
+ - "*.ts" # Also those in the root directory!
126
+ - "*.js"
127
+ - "*.json" # Don't forget about assets!
128
+ - node_modules/ # And large vendored directories
129
+ # And these ignore all the artifacts the build produces:
130
+ - .sass-cache/
131
+ - .jekyll-cache/
132
+ - gemfiles/
133
+ - Gemfile
134
+ - Gemfile.lock
135
+ - vendor/bundle/
136
+ - vendor/cache/
137
+ - vendor/gems/
138
+ - vendor/ruby/
139
+ ```
140
+
141
+ > [!CAUTION]
142
+ >
143
+ > For private repositories, make sure you exclude your source code files from the Jekyll
144
+ > build, or they might be publicly deployed! Also exclude large vendored package
145
+ > directories such as `node_modules/`.
146
+
147
+ ### Add a `Gemfile`:
148
+
149
+ ```ruby
150
+ source 'https://rubygems.org'
151
+
152
+ gem 'jekyll'
153
+ group :jekyll_plugins do
154
+ gem 'jekyll-gfm-admonitions'
155
+ gem 'jekyll-optional-front-matter'
156
+ gem 'github-pages'
157
+ end
158
+ gem 'jekyll-remote-theme'
159
+ ```
160
+
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
+
95
183
  ## License
96
184
 
97
185
  This project is licensed under the MIT License. See the [LICENSE.txt](LICENSE.txt) file
@@ -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)
@@ -44,8 +45,13 @@ module JekyllGFMAdmonitions
44
45
 
45
46
  # Process admonitions in pages
46
47
  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
+
47
54
  Jekyll.logger.debug 'GFMA:', "Processing page '#{page.path}' (#{page.content.length} characters)."
48
- Jekyll.logger.debug 'GFMA:', "#{page.content.inspect}"
49
55
  process(page)
50
56
  end
51
57
 
@@ -57,7 +63,8 @@ module JekyllGFMAdmonitions
57
63
  convert_admonitions(doc)
58
64
 
59
65
  return unless doc.content != original_content
60
-
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)
61
68
  @@admonition_pages << doc
62
69
  @converted += 1
63
70
  end
@@ -67,6 +74,15 @@ module JekyllGFMAdmonitions
67
74
  end
68
75
 
69
76
  def convert_admonitions(doc)
77
+ code_blocks = []
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|
81
+ code_blocks << match
82
+ "```{{CODE_BLOCK_#{code_blocks.length - 1}}}```"
83
+ end
84
+
85
+ # Match the admonition syntax
70
86
  doc.content.gsub!(/>\s*\[!(IMPORTANT|NOTE|WARNING|TIP|CAUTION)\]\s*\n((?:>.*\n?)*)/) do
71
87
  type = ::Regexp.last_match(1).downcase
72
88
  title = type.capitalize
@@ -74,22 +90,31 @@ module JekyllGFMAdmonitions
74
90
  icon = Octicons::Octicon.new(ADMONITION_ICONS[type]).to_svg
75
91
  Jekyll.logger.debug 'GFMA:', "Converting #{type} admonition."
76
92
 
93
+ # Replace them by the GFM admonition HTML
77
94
  "<div class='markdown-alert markdown-alert-#{type}'>
78
95
  <p class='markdown-alert-title'>#{icon} #{title}</p>
79
96
  <p>#{@markdown.convert(text)}</p>
80
97
  </div>\n\n"
81
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
82
104
  end
83
105
  end
84
106
 
85
- Jekyll::Hooks.register :site, :post_render do |site|
86
- Jekyll.logger.info 'GFMA:', "Injecting admonition CSS in #{GFMAdmonitionConverter.admonition_pages.length} page(s)."
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)."
87
110
 
88
- for page in GFMAdmonitionConverter.admonition_pages do
111
+ GFMAdmonitionConverter.admonition_pages.each do |page|
89
112
  Jekyll.logger.debug 'GFMA:', "Appending admonition style to '#{page.path}'."
90
113
  css = File.read(File.expand_path('../assets/admonitions.css', __dir__))
91
114
 
92
- page.output += "<style>#{CSSminify.compress(css)}</style>"
115
+ page.output.gsub!(/<head>(.*?)<\/head>/m) do |match|
116
+ "#{match[0..-7]}<style>#{CSSminify.compress(css)}</style>#{match[-7..-1]}"
117
+ end
93
118
  end
94
119
  end
95
120
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-gfm-admonitions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin De Schepper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-27 00:00:00.000000000 Z
11
+ date: 2024-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll