Skip to content

Commit ecae93a

Browse files
update to internal commit 003bd576
1 parent 7882142 commit ecae93a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

_plugins/custom_alerts.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
module Jekyll
22
Jekyll::Hooks.register [:pages, :posts, :documents], :post_render do |doc|
3-
next unless doc.output && !doc.output.nil?
4-
next unless doc.path.end_with?(".md")
3+
next unless doc.output && doc.path&.end_with?(".md")
54
next unless doc.output.include?("[!")
65

7-
doc.output.gsub!(/<blockquote>\s*<p>\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*?)<\/p>\s*<\/blockquote>/mi) do
6+
doc.output.gsub!(%r{<blockquote>(.*?)</blockquote>}mi) do |match|
7+
inner = $1.dup
8+
9+
unless inner =~ /\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]/i
10+
next match
11+
end
12+
813
type = $1.downcase
9-
text = $2.strip
1014

11-
<<~HTML
12-
<blockquote class="blockquote-#{type}">#{text}</blockquote>
13-
HTML
15+
inner.sub!(/\s*\[!(?:NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*/i, '')
16+
17+
inner.gsub!(%r{<p>\s*</p>}mi, '')
18+
19+
%(<blockquote class="blockquote-#{type}">#{inner}</blockquote>)
1420
end
1521
end
1622
end

0 commit comments

Comments
 (0)