Class: Nexmo::Markdown::MermaidFilter

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

Constant Summary collapse

TYPES =
{
  'mermaid' => '',
  'sequence_diagram' => 'sequenceDiagram',
}.freeze

Instance Method Summary collapse

Instance Method Details

#call(input) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/nexmo_markdown_renderer/filters/mermaid_filter.rb', line 9

def call(input)
  TYPES.each do |markdown, mermaid|
    input = input.gsub(/```#{markdown}(.+?)```/m) do |_s|
      render_mermaid(mermaid, $1)
    end
  end
    
  input
end

#render_mermaid(type, content) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/nexmo_markdown_renderer/filters/mermaid_filter.rb', line 19

def render_mermaid(type, content)
  diagram = "    <div class=\"mermaid\" style=\"color: transparent;\">\#{type} \#{content.gsub('\\\\n', '<br />').strip}\n    </div>\n  HEREDOC\n    \n  \"FREEZESTART\#{Base64.urlsafe_encode64(diagram)}FREEZEEND\"\nend\n"