Welcome to mirror list, hosted at ThFree Co, Russian Federation.

convert_mermaid_html.rb « filters « lib - gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 770502b18f82c7faea529cf62c464c7f1f27c1fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# frozen_string_literal: true

class ConvertMermaidHtml < Nanoc::Filter
  identifier :convert_mermaid_html

  MERMAID_HTML_PATTERN = %r{<div\ class="mermaid">(?<mermaid_content>.*?)</div>}mx

  def run(content, params = {})
    content.gsub(MERMAID_HTML_PATTERN) { generate(Regexp.last_match[:mermaid_content]) }
  end

  def generate(content)
    fixed_content = content
      .gsub('&', '&amp;')
      .gsub('<', '&lt;')
      .gsub('>', '&gt;')
      .gsub('"', '&quot;')

    %(<div class="mermaid">#{fixed_content}</div>)
  end
end