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

mermaid_block_processor.rb « asciidoc « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 03d1c7f1961ba0182558b394a79ce0eb3ec88850 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

require 'asciidoctor'

module Gitlab
  module Asciidoc
    # Mermaid BlockProcessor
    class MermaidBlockProcessor < ::Asciidoctor::Extensions::BlockProcessor
      use_dsl

      named :mermaid
      on_context :literal, :listing
      parse_content_as :simple

      def process(parent, reader, attrs)
        create_mermaid_source_block(parent, reader.read, attrs)
      end

      private

      def create_mermaid_source_block(parent, content, attrs)
        # If "subs" attribute is specified, substitute accordingly.
        # Be careful not to specify "specialcharacters" or your diagram code won't be valid anymore!
        subs = attrs['subs']
        content = parent.apply_subs(content, parent.resolve_subs(subs)) if subs
        html = %(<div><pre data-mermaid-style="display">#{CGI.escape_html(content)}</pre></div>)
        ::Asciidoctor::Block.new(parent, :pass, {
          content_model: :raw,
          source: html,
          subs: :default
        }.merge(attrs))
      end
    end
  end
end