jekyll-gfm-admonitions 1.1.1 → 1.1.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -7
  3. data/lib/jekyll-gfm-admonitions.rb +19 -14
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16b7f7084dea16091c3321713b05fc985b808ccaafd2519642ab588136780312
4
- data.tar.gz: 9ddd8f079018c26d9d956a3f549c805a981c062560ff8bd9183a1f15bae9bac1
3
+ metadata.gz: 256820fe6bdbfbbc0126d749dd40c452fe5a427a68d4d0214435bd7d626585d2
4
+ data.tar.gz: ae6b4e10f370c68a552239d7ffa47cae58a4cfabaa672ccee10d0ea488651a56
5
5
  SHA512:
6
- metadata.gz: 173314afc48352495d02cc2cbeaee5fc9329efefc5d125db43ddf8528e38b52e1f2abde193dc4e125365f8f964d5326975d8b0318c6cef0ae07080049748c93e
7
- data.tar.gz: '0955ccb5f8568a9b940d7031017b66565bd43070d2f101033add90105be806385bf58529b32c3c75c6626cef5e3e03e0f21f20f15f570ade6772d58c6704151f'
6
+ metadata.gz: cbb64978e02ef1359719666c14c4c12d3de465e5af5eb69a8c4656a887ca7a923ce037d6f057c72481f44ad55430d8d1facc161ad9c1568c387e87e85b13455a
7
+ data.tar.gz: 4646e448f77f52e31a06d525b340635d1398d1fc32d2b0ff8509eb90d2340a396e9b934dfb5d01a36b191e9499104bd68f1879650d91c71b9a6fa677eede90c9
data/README.md CHANGED
@@ -29,8 +29,9 @@ The following admonitions are supported:
29
29
  To use admonitions in your markdown files, simply add the following syntax:
30
30
 
31
31
  ```markdown
32
- > [!NOTE]
32
+ > [!NOTE]
33
33
  > Highlights information that users should take into account, even when skimming.
34
+ > And supports multi-line text.
34
35
 
35
36
  > [!TIP]
36
37
  > Optional information to help a user be more successful.
@@ -38,15 +39,18 @@ To use admonitions in your markdown files, simply add the following syntax:
38
39
  > [!IMPORTANT]
39
40
  > Crucial information necessary for users to succeed.
40
41
 
41
- > [!WARNING]
42
- > Critical content demanding immediate user attention due to potential risks.
42
+ > [!WARNING]
43
+ > Critical content demanding immediate
44
+ > user attention due to potential risks.
43
45
 
44
46
  > [!CAUTION]
45
47
  > Negative potential consequences of an action.
48
+ > Opportunity to provide more context.
46
49
  ```
47
50
 
48
- > [!NOTE]
51
+ > [!NOTE]
49
52
  > Highlights information that users should take into account, even when skimming.
53
+ > And supports multi-line text.
50
54
 
51
55
  > [!TIP]
52
56
  > Optional information to help a user be more successful.
@@ -54,11 +58,13 @@ To use admonitions in your markdown files, simply add the following syntax:
54
58
  > [!IMPORTANT]
55
59
  > Crucial information necessary for users to succeed.
56
60
 
57
- > [!WARNING]
58
- > Critical content demanding immediate user attention due to potential risks.
61
+ > [!WARNING]
62
+ > Critical content demanding immediate
63
+ > user attention due to potential risks.
59
64
 
60
65
  > [!CAUTION]
61
66
  > Negative potential consequences of an action.
67
+ > Opportunity to provide more context.
62
68
 
63
69
  #### Custom titles
64
70
 
@@ -179,4 +185,6 @@ for details.
179
185
 
180
186
  ## Contributing
181
187
 
182
- Contributions are welcome! Please feel free to submit issues or pull requests.
188
+
189
+ > [!TIP]
190
+ > Contributions are welcome! Please feel free to submit issues or pull requests.
@@ -73,6 +73,12 @@ module JekyllGFMAdmonitions
73
73
  end
74
74
 
75
75
  def process_doc(doc)
76
+ # Return early if content is empty
77
+ return if doc.content.empty?
78
+
79
+ # If the content is frozen, we need to duplicate it so that we can modify it
80
+ doc.content = doc.content.dup unless doc.content.frozen?
81
+
76
82
  code_blocks = []
77
83
  # Temporarily replace code blocks by a tag, so that we don't process any admonitions
78
84
  # inside of code blocks.
@@ -90,26 +96,25 @@ module JekyllGFMAdmonitions
90
96
  end
91
97
 
92
98
  def convert_admonitions(doc)
93
- doc.content.gsub!(/>\s*\[!(IMPORTANT|NOTE|WARNING|TIP|CAUTION)\]\s*(.*)\s*\n((?:>.*\n?)*)/) do
94
- type = ::Regexp.last_match(1).downcase
95
- if ::Regexp.last_match(2).length > 0
96
- title = ::Regexp.last_match(2)
97
- else
98
- title = type.capitalize
99
- end
100
- text = ::Regexp.last_match(3).gsub(/^>\s*/, '').strip
101
- icon = Octicons::Octicon.new(ADMONITION_ICONS[type]).to_svg
102
- Jekyll.logger.debug 'GFMA:', "Converting #{type} admonition."
99
+ doc.content.gsub!(/^(\s*)>\s*\[!(IMPORTANT|NOTE|WARNING|TIP|CAUTION)\]([^\n]*)\n((?:\1\s*>\s*[^\n]*(?:\n|$))(?:(?!\s*>\s*\[!)\1\s*>\s*[^\n]*(?:\n|$))*)/) do
100
+ initial_indent = ::Regexp.last_match(1)
101
+ type = ::Regexp.last_match(2).downcase
102
+ title = ::Regexp.last_match(3).strip.empty? ? type.capitalize : ::Regexp.last_match(3).strip
103
+ text = ::Regexp.last_match(4).gsub(/^#{Regexp.escape(initial_indent)}\s*>\s*/, '').strip
103
104
 
105
+ icon = Octicons::Octicon.new(ADMONITION_ICONS[type]).to_svg
104
106
  admonition_html(type, title, text, icon)
105
107
  end
108
+
109
+ # 🛠 Ensure a blank line exists after each admonition block to prevent Markdown parsing issues.
110
+ doc.content.gsub!(/(<\/div>)(?!\n\n)/, "\\1\n\n")
106
111
  end
107
112
 
108
113
  def admonition_html(type, title, text, icon)
109
- "<div class='markdown-alert markdown-alert-#{type}'>
110
- <p class='markdown-alert-title'>#{icon} #{title}</p>
111
- <p>#{@markdown.convert(text)}</p>
112
- </div>\n\n"
114
+ "<div class='markdown-alert markdown-alert-#{type}'>" \
115
+ "<p class='markdown-alert-title'>#{icon} #{title}</p>" \
116
+ "#{@markdown.convert(text)}" \
117
+ "</div>"
113
118
  end
114
119
  end
115
120
 
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.1.1
4
+ version: 1.1.2
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: 2025-02-14 00:00:00.000000000 Z
11
+ date: 2025-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cssminify