Class: Nexmo::Markdown::CollapsibleFilter

Inherits:
Banzai::Filter
  • Object
show all
Defined in:
lib/nexmo_markdown_renderer/filters/collapsible_filter.rb

Instance Method Summary collapse

Instance Method Details

#call(input) ⇒ Object

Transforms matching input into a collapsible HTML element on NDP. Matching input example: | ## Headingn|nContentnn



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/nexmo_markdown_renderer/filters/collapsible_filter.rb', line 7

def call(input)
  input.gsub(/^\|\s(\#{1,6})(\s)?(.+?)\n^\|\n(.+?)\n\n/m) do |_s|
    heading = $3
    body = $4.gsub(/^\|\n/, "\n")
    body = body.gsub(/^\|\s/, '')
    parsed_body = Nexmo::Markdown::Renderer.new.call(body)
    
    <<~HEREDOC
      <div class="Vlt-accordion Vlt-box Vlt-box--lesspadding Nxd-accordion-emphasis">
        <h5 class="Vlt-accordion__trigger"  tabindex="0">#{heading}</h5>
        <div class="Vlt-accordion__content Vlt-accordion__content--noborder">
          #{parsed_body}
        </div>
      </div>
    HEREDOC
  end
end