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: c788137e1225325f6fba076585d06e721606377c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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]]

          before = $~[:before]
          before = "\n#{before}" if $~[:encoding].presence

          "#{before}```#{lang}:frontmatter\n#{$~[:front_matter]}```\n"
        end
      end
    end
  end
end