jekyll-gfm-admonitions 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 73f62b9375b8f6b7d657aba5597cab2d612a70350d044af9807bbee619774aa1
4
+ data.tar.gz: 06e4c485c9d50d38fdb22e9ac7228ea431f8f55e41c808af6a73837cf34037fa
5
+ SHA512:
6
+ metadata.gz: 299f06fe2684ed5b9f792decd2c1d666af9f17906f4c65413de499f526f5636eb834101ef95be18a93d9ec28e79cea4b0d49eafc8001792b1a0c8859b7f9be01
7
+ data.tar.gz: 11e51faa997ee7d745814a2d8761a36020273c559c5b492dbbcab07e4379e4d0d8469dd8b56e5429522258084b533e0bdcbb6581f26a4348933b07eea93e79e5
data/LICENSE.txt ADDED
@@ -0,0 +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.
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # GitHub Flavored Admonitions
2
+
3
+ A Jekyll plugin to render GitHub-flavored admonitions in your Jekyll sites.
4
+ This plugin allows you to use GitHub-flavored markdown syntax to create stylish admonition
5
+ blocks for notes, warnings, tips, cautions, and important messages.
6
+
7
+ ## Supported Admonitions
8
+
9
+ The following admonitions are supported:
10
+
11
+ - **Important**: `> [!IMPORTANT]`
12
+ - **Note**: `> [!NOTE]`
13
+ - **Tip**: `> [!TIP]`
14
+ - **Warning**: `> [!WARNING]`
15
+ - **Caution**: `> [!CAUTION]`
16
+
17
+ ### Example Usage
18
+
19
+ To use admonitions in your markdown files, simply add the following syntax:
20
+
21
+ ```markdown
22
+ > [!IMPORTANT]
23
+ > This is an important message.
24
+
25
+ > [!NOTE]
26
+ > This is a note.
27
+
28
+ > [!TIP]
29
+ > This is a helpful tip.
30
+
31
+ > [!WARNING]
32
+ > This is a warning.
33
+
34
+ > [!CAUTION]
35
+ > This is a caution message.
36
+ ```
37
+
38
+ > [!IMPORTANT]
39
+ > This is an important message.
40
+
41
+ > [!NOTE]
42
+ > This is a note.
43
+
44
+ > [!TIP]
45
+ > This is a helpful tip.
46
+
47
+ > [!WARNING]
48
+ > This is a warning.
49
+
50
+ > [!CAUTION]
51
+ > This is a caution message.
52
+
53
+ ## Installation
54
+
55
+ To install the plugin, add it to your Jekyll project's `Gemfile`:
56
+
57
+ ```ruby
58
+ group :jekyll_plugins do
59
+
60
+ # Other plugins go here ...
61
+
62
+ # ... Add this line:
63
+ gem "jekyll-gfm-admonitions"
64
+ end
65
+ ```
66
+
67
+ Then run:
68
+
69
+ ```bash
70
+ bundle install
71
+ ```
72
+
73
+ ### Configuring Jekyll
74
+
75
+ Next, you need to enable the plugin in your Jekyll configuration file (`_config.yml`):
76
+
77
+ ```yaml
78
+ plugins:
79
+ - jekyll-gfm-admonitions
80
+ ```
81
+
82
+ Then, during build/serve, you should see a log similar to:
83
+
84
+ ```
85
+ GFMA: Converted adminitions in 1 file(s).
86
+ ```
87
+
88
+ ## When using GitHub Pages
89
+
90
+ To enable custom plugins in your Jekyll build for GitHub Pages, you need to use GitHub
91
+ Actions (GHA) to build and deploy your Jekyll site. For detailed instructions on setting
92
+ up GitHub Actions for your Jekyll project, please follow this link:
93
+ [GitHub Actions Setup for Jekyll](https://jekyllrb.com/docs/continuous-integration/github-actions/).
94
+
95
+ ## License
96
+
97
+ This project is licensed under the MIT License. See the [LICENSE.txt](LICENSE.txt) file
98
+ for details.
99
+
100
+ ## Contributing
101
+
102
+ Contributions are welcome! Please feel free to submit issues or pull requests.
@@ -0,0 +1,73 @@
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 svg path {
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;
73
+ }
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'octicons'
4
+ require 'cssminify'
5
+
6
+ ADMONITION_ICONS = {
7
+ 'important' => 'report',
8
+ 'note' => 'info',
9
+ 'tip' => 'light-bulb',
10
+ 'warning' => 'alert',
11
+ 'caution' => 'stop'
12
+ }.freeze
13
+
14
+ # JekyllGFMAdmonitions is a module that provides functionality to process and
15
+ # convert GitHub-flavored markdown admonitions into HTML within Jekyll.
16
+ module JekyllGFMAdmonitions
17
+ # GFMAdmonitionConverter is a Jekyll generator that converts custom
18
+ # admonition blocks in markdown (e.g., `> [!IMPORTANT]`) into styled HTML
19
+ # alert boxes with icons.
20
+ #
21
+ # This generator processes both posts and pages, replacing admonition
22
+ # syntax with HTML markup that includes appropriate iconography and CSS styling.
23
+ class GFMAdmonitionConverter < Jekyll::Generator
24
+ safe true
25
+
26
+ def initialize(*args)
27
+ super(*args)
28
+ @converted = 0
29
+ end
30
+
31
+ def generate(site)
32
+ # Process admonitions in posts
33
+ site.posts.docs.each do |doc|
34
+ process(doc)
35
+ end
36
+
37
+ # Process admonitions in pages
38
+ site.pages.each do |page|
39
+ process(page)
40
+ end
41
+
42
+ Jekyll.logger.info 'GFMA:', "Converted adminitions in #{@converted} file(s)."
43
+ end
44
+
45
+ def process(doc)
46
+ original_content = doc.content.dup
47
+ convert_admonitions(doc)
48
+
49
+ return unless doc.content != original_content
50
+
51
+ inject_css(doc)
52
+ @converted += 1
53
+ end
54
+
55
+ def convert_admonitions(doc)
56
+ doc.content.gsub!(/>\s*\[!(IMPORTANT|NOTE|WARNING|TIP|CAUTION)\]\s*\n((?:>.*\n?)*)/) do
57
+ type = ::Regexp.last_match(1).downcase
58
+ title = type.capitalize
59
+ text = ::Regexp.last_match(2).gsub(/^>\s*/, '').strip
60
+ icon = Octicons::Octicon.new(ADMONITION_ICONS[type]).to_svg
61
+
62
+ "<div class='markdown-alert markdown-alert-#{type}'>
63
+ <p class='markdown-alert-title'>#{icon} #{title}</p>
64
+ <p>#{text}</p>
65
+ </div>"
66
+ end
67
+ end
68
+
69
+ def inject_css(doc)
70
+ css = File.read(File.expand_path('../assets/admonitions.css', __dir__))
71
+ doc.content += "<style>#{CSSminify.compress(css)}</style>"
72
+ end
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-gfm-admonitions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robin De Schepper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ description: This plugin allows you to use GitHub-flavored markdown syntaxto create
42
+ admonition blocks in Jekyll sites.
43
+ email:
44
+ - robin.deschepper93@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE.txt
50
+ - README.md
51
+ - assets/admonitions.css
52
+ - lib/jekyll-gfm-admonitions.rb
53
+ homepage: https://github.com/helveg/jekyll-gfm-admonitions
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.7.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.5.20
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: A Jekyll plugin to render GitHub-flavored admonitions.
76
+ test_files: []