Class: Jekyll::CalloutBlock

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/jekyll/callout_tag.rb

Constant Summary collapse

VALID_TYPES =
%w[note tip warning danger info].freeze
DEFAULT_TITLES =
{
  "note"    => "Note",
  "tip"     => "Tip",
  "warning" => "Warning",
  "danger"  => "Danger",
  "info"    => "Info"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ CalloutBlock

Returns a new instance of CalloutBlock.



18
19
20
21
# File 'lib/jekyll/callout_tag.rb', line 18

def initialize(tag_name, markup, tokens)
  super
  @type, @title = parse_markup(markup.strip)
end

Instance Method Details

#render(context) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/jekyll/callout_tag.rb', line 23

def render(context)
  raw_content = super
  rendered_body = Kramdown::Document.new(raw_content.strip).to_html.strip

  title_html = if @title && !@title.empty?
    "  <div class=\"callout__title\">#{@title}</div>\n"
  else
    ""
  end

  <<~HTML.strip
    <div class="callout callout--#{@type}">
    #{title_html}  <div class="callout__body">
      #{rendered_body}
      </div>
    </div>
  HTML
end