Module: MdocsKramdown::Parser::FencedCollapsibleAdmonitions

Included in:
Kramdown::Parser::MdocsKramdown
Defined in:
lib/mdocs_kramdown/parser/fenced_collapsible_admonitions.rb

Constant Summary collapse

FENCED_COLLAPSIBLE_ADMONITIONS_START =
/^\s{0,}\?{3}/x.freeze
FENCED_COLLAPSIBLE_ADMONITIONS_MATCH =
%r{
\s{0,}*(?<delimiter>\?{3})       # line must start with [0..] spacing and !!!
\s?
(?<type>[^\s]+)?                # type of admoniation any except space. Ex: info,class1
\s?
("(?<title>[^\n]+)")?           # title of the admoniation
\n
(?<content>(\s{4}.+)+)          # content must starts with 4 spaces
\n}x.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



16
17
18
# File 'lib/mdocs_kramdown/parser/fenced_collapsible_admonitions.rb', line 16

def self.included(klass)
  klass.define_parser(:fenced_collapsible_admonitions, FENCED_COLLAPSIBLE_ADMONITIONS_START)
end

Instance Method Details

#parse_fenced_collapsible_admonitionsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mdocs_kramdown/parser/fenced_collapsible_admonitions.rb', line 20

def parse_fenced_collapsible_admonitions
  if @src.check(FENCED_COLLAPSIBLE_ADMONITIONS_MATCH)
    start_line_number = @src.current_line_number
    @src.pos += @src.matched_size

    el = new_block_el(:blockquote, nil, { types: @src[:type].to_s.split(','), title: @src[:title] }, location: start_line_number, admonition: true, collapsible: true)

    content = parse_inner_alert_content(@src[:content].gsub(/^\s{4}/, ''))
    el.children = content
    @tree.children << el
    true
  else
    false
  end
end

#parse_inner_alert_content(content) ⇒ Object



36
37
38
39
# File 'lib/mdocs_kramdown/parser/fenced_collapsible_admonitions.rb', line 36

def parse_inner_alert_content(content)
  parsed = ::Kramdown::Parser::MdocsKramdown.parse(content, @options)
  parsed[0].children
end