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

front_matter_filter.rb « filter « banzai « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5900e76224483a502dd34f4155f055aa04984308 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# frozen_string_literal: true

module Banzai
  module Filter
    class FrontMatterFilter < HTML::Pipeline::Filter
      def call
        lang_mapping = Gitlab::FrontMatter::DELIM_LANG

        html.sub(Gitlab::FrontMatter::PATTERN) do |_match|
          lang = $~[:lang].presence || lang_mapping[$~[:delim]]

          ["```#{lang}", $~[:front_matter], "```", "\n"].join("\n")
        end
      end
    end
  end
end