jekyll-gfm-admonitions 1.0.2 → 1.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e430262ea2a0d62b88656fc9d61a244f4840e6ae0a67699440f64c129671c98
4
- data.tar.gz: 580f689cdf7e6072108a039164198ef17dd32e160879d7fdfc0ffe7dcce24ac6
3
+ metadata.gz: 55602a9eb6c0421b49d053f7c5d632d3688d13fe4b200c9b46df7e28fa13082b
4
+ data.tar.gz: 9bac7b962095054d91543ff318dd525f1b171a6998bcd880d58b64d991a6b1a8
5
5
  SHA512:
6
- metadata.gz: 27109d0a6495fbec17fd52b46872362a3fa056832e5faa16a8837b77c4f4596c0177a08c9f53e020312370046530d9afd7f80bdaa7315245c30b9235ffd59bbc
7
- data.tar.gz: eae65a1558f810cdd52d8af2b5cc91d8acfc210ae6cf5380f9047766baa94aff5961c20084793c486cb612100b7bd4aa621e3024adfe48878404b737b1d5f115
6
+ metadata.gz: 17d54f579fa4ff3f59c4ef4473f664c044207f86ada2710e46fba9afa79aa181b0df9ef3abdda9c5a4eb42a018fd55ff3e3448bf56ca60b70eec553abda728e6
7
+ data.tar.gz: 3fb3cd143db748991579039b9d0704dc1490e080cb49c02132b308fe68553f370f5344fed0d91f2f914bb85ea7750609e2a1786066ed0f3008e4f138fc2a8d2e
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Robin De Schepper
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- - The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Robin De Schepper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ - The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -8,47 +8,50 @@ blocks for notes, warnings, tips, cautions, and important messages.
8
8
 
9
9
  The following admonitions are supported:
10
10
 
11
- - **Important**: `> [!IMPORTANT]`
12
- - **Note**: `> [!NOTE]`
13
- - **Tip**: `> [!TIP]`
14
- - **Warning**: `> [!WARNING]`
15
- - **Caution**: `> [!CAUTION]`
11
+ | **Type** | **Markdown** |
12
+ |---------------|-----------------------|
13
+ | Note | `> [!NOTE]` |
14
+ | Tip | `> [!TIP]` |
15
+ | Important | `> [!IMPORTANT]` |
16
+ | Warning | `> [!WARNING]` |
17
+ | Caution | `> [!CAUTION]` |
18
+
16
19
 
17
20
  ### Example Usage
18
21
 
19
22
  To use admonitions in your markdown files, simply add the following syntax:
20
23
 
21
24
  ```markdown
22
- > [!IMPORTANT]
23
- > This is an **important** message.
24
-
25
- > [!NOTE]
26
- > This is a **note**.
25
+ > [!NOTE]
26
+ > Highlights information that users should take into account, even when skimming.
27
27
 
28
28
  > [!TIP]
29
- > This is a **helpful** tip.
29
+ > Optional information to help a user be more successful.
30
+
31
+ > [!IMPORTANT]
32
+ > Crucial information necessary for users to succeed.
30
33
 
31
- > [!WARNING]
32
- > This is a **warning**.
34
+ > [!WARNING]
35
+ > Critical content demanding immediate user attention due to potential risks.
33
36
 
34
37
  > [!CAUTION]
35
- > This is a **caution** message.
38
+ > Negative potential consequences of an action.
36
39
  ```
37
40
 
38
- > [!IMPORTANT]
39
- > This is an **important** message.
40
-
41
- > [!NOTE]
42
- > This is a **note**.
41
+ > [!NOTE]
42
+ > Highlights information that users should take into account, even when skimming.
43
43
 
44
44
  > [!TIP]
45
- > This is a **helpful** tip.
45
+ > Optional information to help a user be more successful.
46
+
47
+ > [!IMPORTANT]
48
+ > Crucial information necessary for users to succeed.
46
49
 
47
- > [!WARNING]
48
- > This is a **warning**.
50
+ > [!WARNING]
51
+ > Critical content demanding immediate user attention due to potential risks.
49
52
 
50
53
  > [!CAUTION]
51
- > This is a **caution** message.
54
+ > Negative potential consequences of an action.
52
55
 
53
56
  ## Installation
54
57
 
@@ -1,73 +1,69 @@
1
- .markdown-alert {
2
- padding: 0.5rem 1rem;
3
- margin-bottom: 1rem;
4
- color: inherit;
5
- border-left: .25em solid #30363d;
6
- }
7
-
8
- .markdown-body .markdown-alert > :first-child {
9
- margin-top: 0;
10
- }
11
-
12
- .markdown-body .markdown-alert > :last-child {
13
- margin-bottom: 0;
14
- }
15
-
16
- .markdown-body .markdown-alert .markdown-alert-title {
17
- display: flex;
18
- font-weight: 500;
19
- align-items: center;
20
- line-height: 1;
21
- }
22
-
23
- .markdown-body .markdown-alert svg {
24
- margin-right: 0.5rem !important;
25
- }
26
-
27
- .markdown-body .markdown-alert svg path {
28
- fill: currentColor;
29
- }
30
-
31
- .markdown-body .markdown-alert.markdown-alert-note {
32
- border-left-color: #4493f8;
33
- }
34
-
35
- .markdown-body .markdown-alert.markdown-alert-note .markdown-alert-title {
36
- color: #4493f8;
37
- }
38
-
39
- .markdown-body .markdown-alert.markdown-alert-important {
40
- border-left-color: #ab7df8;
41
- }
42
-
43
- .markdown-body .markdown-alert.markdown-alert-important .markdown-alert-title {
44
- color: #ab7df8;
45
- }
46
-
47
- .markdown-body .markdown-alert.markdown-alert-warning {
48
- border-left-color: #9e6a03;
49
- }
50
-
51
- .markdown-body .markdown-alert.markdown-alert-warning .markdown-alert-title {
52
- color: #d29922;
53
- }
54
-
55
- .markdown-body .markdown-alert.markdown-alert-tip {
56
- border-left-color: #238636;
57
- }
58
-
59
- .markdown-body .markdown-alert.markdown-alert-tip .markdown-alert-title {
60
- color: #3fb950;
61
- }
62
-
63
- .markdown-body .markdown-alert.markdown-alert-caution {
64
- border-left-color: #da3633;
65
- }
66
-
67
- .markdown-body .markdown-alert.markdown-alert-caution .markdown-alert-title {
68
- color: #f85149;
69
- }
70
-
71
- .markdown-body > :first-child > .heading-element:first-child {
72
- margin-top: 0 !important;
1
+ .markdown-alert {
2
+ padding: 0.5rem 1rem;
3
+ margin-bottom: 1rem;
4
+ color: inherit;
5
+ border-left: .25em solid #30363d;
6
+ }
7
+
8
+ .markdown-alert > :first-child {
9
+ margin-top: 0;
10
+ }
11
+
12
+ .markdown-alert > :last-child {
13
+ margin-bottom: 0;
14
+ }
15
+
16
+ .markdown-alert .markdown-alert-title {
17
+ display: flex;
18
+ font-weight: 500;
19
+ align-items: center;
20
+ line-height: 1;
21
+ }
22
+
23
+ .markdown-alert svg {
24
+ margin-right: 0.5rem !important;
25
+ }
26
+
27
+ .markdown-alert svg path {
28
+ fill: currentColor;
29
+ }
30
+
31
+ .markdown-alert.markdown-alert-note {
32
+ border-left-color: #4493f8;
33
+ }
34
+
35
+ .markdown-alert.markdown-alert-note .markdown-alert-title {
36
+ color: #4493f8;
37
+ }
38
+
39
+ .markdown-alert.markdown-alert-important {
40
+ border-left-color: #ab7df8;
41
+ }
42
+
43
+ .markdown-alert.markdown-alert-important .markdown-alert-title {
44
+ color: #ab7df8;
45
+ }
46
+
47
+ .markdown-alert.markdown-alert-warning {
48
+ border-left-color: #9e6a03;
49
+ }
50
+
51
+ .markdown-alert.markdown-alert-warning .markdown-alert-title {
52
+ color: #d29922;
53
+ }
54
+
55
+ .markdown-alert.markdown-alert-tip {
56
+ border-left-color: #238636;
57
+ }
58
+
59
+ .markdown-alert.markdown-alert-tip .markdown-alert-title {
60
+ color: #3fb950;
61
+ }
62
+
63
+ .markdown-alert.markdown-alert-caution {
64
+ border-left-color: #da3633;
65
+ }
66
+
67
+ .markdown-alert.markdown-alert-caution .markdown-alert-title {
68
+ color: #f85149;
73
69
  }
@@ -1,124 +1,132 @@
1
- # frozen_string_literal: true
2
-
3
- require 'octicons'
4
- require 'cssminify'
5
- require 'liquid/template'
6
-
7
- ADMONITION_ICONS = {
8
- 'important' => 'report',
9
- 'note' => 'info',
10
- 'tip' => 'light-bulb',
11
- 'warning' => 'alert',
12
- 'caution' => 'stop'
13
- }.freeze
14
-
15
- # JekyllGFMAdmonitions is a module that provides functionality to process and
16
- # convert GitHub-flavored markdown admonitions into HTML within Jekyll.
17
- module JekyllGFMAdmonitions
18
- # GFMAdmonitionConverter is a Jekyll generator that converts custom
19
- # admonition blocks in markdown (e.g., `> [!IMPORTANT]`) into styled HTML
20
- # alert boxes with icons.
21
- #
22
- # This generator processes both posts and pages, replacing admonition
23
- # syntax with HTML markup that includes appropriate iconography and CSS styling.
24
- class GFMAdmonitionConverter < Jekyll::Generator
25
- safe true
26
- priority :lowest
27
- @admonition_pages = []
28
-
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)."
35
- end
36
-
37
- def init_converter(site)
38
- @markdown = site.converters.find { |c| c.is_a?(Jekyll::Converters::Markdown) }
39
- return if @markdown
40
-
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)
46
- site.posts.docs.each do |doc|
47
- Jekyll.logger.debug 'GFMA:', "Processing post '#{doc.path}' (#{doc.content.length} characters)."
48
- process_doc(doc)
49
- end
50
- end
51
-
52
- def process_pages(site)
53
- site.pages.each do |page|
54
- Jekyll.logger.debug 'GFMA:', "Processing page '#{page.path}' (#{page.content.length} characters)."
55
- process_doc_content(page)
56
- end
57
- end
58
-
59
- def process_doc_content(doc)
60
- original_content = doc.content.dup
61
- process_doc(doc)
62
-
63
- return unless doc.content != original_content
64
-
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
68
- end
69
-
70
- class << self
71
- attr_reader :admonition_pages
72
- end
73
-
74
- def process_doc(doc)
75
- code_blocks = []
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|
79
- code_blocks << match
80
- "```{{CODE_BLOCK_#{code_blocks.length - 1}}}```"
81
- end
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)
92
- doc.content.gsub!(/>\s*\[!(IMPORTANT|NOTE|WARNING|TIP|CAUTION)\]\s*\n((?:>.*\n?)*)/) do
93
- type = ::Regexp.last_match(1).downcase
94
- title = type.capitalize
95
- text = ::Regexp.last_match(2).gsub(/^>\s*/, '').strip
96
- icon = Octicons::Octicon.new(ADMONITION_ICONS[type]).to_svg
97
- Jekyll.logger.debug 'GFMA:', "Converting #{type} admonition."
98
-
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}'>
105
- <p class='markdown-alert-title'>#{icon} #{title}</p>
106
- <p>#{@markdown.convert(text)}</p>
107
- </div>\n\n"
108
- end
109
- end
110
-
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)."
114
-
115
- GFMAdmonitionConverter.admonition_pages.each do |page|
116
- Jekyll.logger.debug 'GFMA:', "Appending admonition style to '#{page.path}'."
117
- css = File.read(File.expand_path('../assets/admonitions.css', __dir__))
118
-
119
- page.output.gsub!(%r{<head>(.*?)</head>}m) do |match|
120
- "#{match[0..-7]}<style>#{CSSminify.compress(css)}</style>#{match[-7..]}"
121
- end
122
- end
123
- end
124
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'octicons'
4
+ require 'cssminify'
5
+ require 'liquid/template'
6
+
7
+ ADMONITION_ICONS = {
8
+ 'important' => 'report',
9
+ 'note' => 'info',
10
+ 'tip' => 'light-bulb',
11
+ 'warning' => 'alert',
12
+ 'caution' => 'stop'
13
+ }.freeze
14
+
15
+ # JekyllGFMAdmonitions is a module that provides functionality to process and
16
+ # convert GitHub-flavored markdown admonitions into HTML within Jekyll.
17
+ module JekyllGFMAdmonitions
18
+ # GFMAdmonitionConverter is a Jekyll generator that converts custom
19
+ # admonition blocks in markdown (e.g., `> [!IMPORTANT]`) into styled HTML
20
+ # alert boxes with icons.
21
+ #
22
+ # This generator processes both posts and pages, replacing admonition
23
+ # syntax with HTML markup that includes appropriate iconography and CSS styling.
24
+ class GFMAdmonitionConverter < Jekyll::Generator
25
+ safe true
26
+ priority :lowest
27
+ @admonition_pages = []
28
+
29
+ class << self
30
+ attr_reader :admonition_pages
31
+ end
32
+
33
+
34
+ def generate(site)
35
+ init_converter(site)
36
+ process_posts(site)
37
+ process_pages(site)
38
+ Jekyll.logger.info 'GFMA:', 'Converted adminitions in' \
39
+ " #{self.class.admonition_pages.length} file(s)."
40
+ end
41
+
42
+ def init_converter(site)
43
+ @markdown = site.converters.find { |c| c.is_a?(Jekyll::Converters::Markdown) }
44
+ return if @markdown
45
+
46
+ raise 'Markdown converter not found. Please ensure that you have a markdown' \
47
+ ' converter configured in your Jekyll site.'
48
+ end
49
+
50
+ def process_posts(site)
51
+ site.posts.docs.each do |doc|
52
+ Jekyll.logger.debug 'GFMA:', "Processing post '#{doc.path}' (#{doc.content.length} characters)."
53
+ process_doc(doc)
54
+ end
55
+ end
56
+
57
+ def process_pages(site)
58
+ site.pages.each do |page|
59
+ Jekyll.logger.debug 'GFMA:', "Processing page '#{page.path}' (#{page.content.length} characters)."
60
+ process_doc_content(page)
61
+ end
62
+ end
63
+
64
+ def process_doc_content(doc)
65
+ original_content = doc.content.dup
66
+ process_doc(doc)
67
+
68
+ return unless doc.content != original_content
69
+
70
+ # Store a reference to all the pages we modified, to inject the CSS post render
71
+ # (otherwise GitHub Pages sanitizes the CSS into plaintext)
72
+ self.class.admonition_pages << doc
73
+ end
74
+
75
+ def process_doc(doc)
76
+ code_blocks = []
77
+ # Temporarily replace code blocks by a tag, so that we don't process any admonitions
78
+ # inside of code blocks.
79
+ doc.content.gsub!(/(?:^|\n)(?<!>)\s*```.*?```/m) do |match|
80
+ code_blocks << match
81
+ "```{{CODE_BLOCK_#{code_blocks.length - 1}}}```"
82
+ end
83
+
84
+ convert_admonitions(doc)
85
+
86
+ # Put the code blocks back in place
87
+ doc.content.gsub!(/```\{\{CODE_BLOCK_(\d+)}}```/) do
88
+ code_blocks[::Regexp.last_match(1).to_i]
89
+ end
90
+ end
91
+
92
+ def convert_admonitions(doc)
93
+ doc.content.gsub!(/>\s*\[!(IMPORTANT|NOTE|WARNING|TIP|CAUTION)\]\s*\n((?:>.*\n?)*)/) do
94
+ type = ::Regexp.last_match(1).downcase
95
+ title = type.capitalize
96
+ text = ::Regexp.last_match(2).gsub(/^>\s*/, '').strip
97
+ icon = Octicons::Octicon.new(ADMONITION_ICONS[type]).to_svg
98
+ Jekyll.logger.debug 'GFMA:', "Converting #{type} admonition."
99
+
100
+ admonition_html(type, title, text, icon)
101
+ end
102
+ end
103
+
104
+ def admonition_html(type, title, text, icon)
105
+ "<div class='markdown-alert markdown-alert-#{type}'>
106
+ <p class='markdown-alert-title'>#{icon} #{title}</p>
107
+ <p>#{@markdown.convert(text)}</p>
108
+ </div>\n\n"
109
+ end
110
+ end
111
+
112
+ # Insert the minified CSS before the closing head tag of all pages we put admonitions on
113
+ Jekyll::Hooks.register :site, :post_render do
114
+ Jekyll.logger.info 'GFMA:', "Inserting admonition CSS in #{GFMAdmonitionConverter.admonition_pages.length} page(s)."
115
+
116
+ GFMAdmonitionConverter.admonition_pages.each do |page|
117
+ Jekyll.logger.debug 'GFMA:', "Appending admonition style to '#{page.path}'."
118
+ css = File.read(File.expand_path('../assets/admonitions.css', __dir__))
119
+
120
+ page.output.gsub!(%r{<head>(.*?)</head>}m) do |match|
121
+ head = Regexp.last_match(1)
122
+ "<head>#{head}<style>#{CSSminify.compress(css)}</style></head>"
123
+ end
124
+
125
+ # If no <head> tag is found, insert the CSS at the start of the output
126
+ if !page.output.match(%r{<head>(.*?)</head>}m)
127
+ Jekyll.logger.debug 'GFMA:', "No <head> tag found in '#{page.path}', inserting CSS at the beginning of the page."
128
+ page.output = "<head><style>#{CSSminify.compress(css)}</style></head>" + page.output
129
+ end
130
+ end
131
+ end
132
+ 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: 1.0.2
4
+ version: 1.0.4
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-28 00:00:00.000000000 Z
11
+ date: 2025-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cssminify
@@ -28,16 +28,22 @@ dependencies:
28
28
  name: jekyll
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '5.0'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '3.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.0'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: octicons
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -97,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
103
  - !ruby/object:Gem::Version
98
104
  version: '0'
99
105
  requirements: []
100
- rubygems_version: 3.5.20
106
+ rubygems_version: 3.5.22
101
107
  signing_key:
102
108
  specification_version: 4
103
109
  summary: A Jekyll plugin to render GitHub-flavored admonitions.