-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkramdown_enhancements.rb
More file actions
65 lines (59 loc) Β· 1.6 KB
/
kramdown_enhancements.rb
File metadata and controls
65 lines (59 loc) Β· 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module Kramdown
module Converter
class Html
def convert_blockquote(el, indent)
first_child = el.children[0]
case first_child.to_h
in {
type: :p,
children: [
{ type: :text, value: /\A\[!(CAUTION|IMPORTANT|NOTE|TIP|WARNING)\]\z/ },
{ type: :br },
*
]
}
# The matching regular expression group.
alert_type = $+.downcase
# Remove the alert type text and trailing <br>.
first_child.children.slice!(0, 2)
header = Element.new(:html_element, :h1, { class: 'alert-heading' })
header.children << Element.new(
:img,
nil,
{
alt: '', # This image is purely decorative.
src: "/images/#{alert_type}.svg",
}
)
header.children << Element.new(:text, alert_type.capitalize)
aside = Element.new(:html_element, :aside)
aside.children << header
aside.children.push(*el.children)
format_as_block_html(
'aside',
{ class: "alert alert-#{alert_type}" },
format_as_indented_block_html(
'div',
{},
inner(aside, indent),
indent
),
indent
)
else
# super.
format_as_indented_block_html('blockquote', el.attr, inner(el, indent), indent)
end
end
end
end
class Element
def to_h
{
children: children.map(&:to_h),
type:,
value:
}
end
end
end