class Nexmo::Markdown::MermaidFilter

Constants

TYPES

Public Instance Methods

call(input) click to toggle source
# 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) click to toggle source
# File lib/nexmo_markdown_renderer/filters/mermaid_filter.rb, line 19
      def render_mermaid(type, content)
        diagram = <<~HEREDOC
          <div class="mermaid" style="color: transparent;">#{type} #{content.gsub('\\n', '<br />').strip}
          </div>
        HEREDOC
    
        "FREEZESTART#{Base64.urlsafe_encode64(diagram)}FREEZEEND"
      end