debian-mirror-gitlab/lib/banzai/filter/front_matter_filter.rb
2023-06-09 12:34:30 +05:30

21 lines
550 B
Ruby

# frozen_string_literal: true
module Banzai
module Filter
class FrontMatterFilter < HTML::Pipeline::Filter
def call
lang_mapping = Gitlab::FrontMatter::DELIM_LANG
Gitlab::FrontMatter::PATTERN_UNTRUSTED_REGEX.replace_gsub(html) do |match|
lang = match[:lang].presence || lang_mapping[match[:delim]]
before = match[:before]
before = "\n#{before}" if match[:encoding].presence
"#{before}```#{lang}:frontmatter\n#{match[:front_matter]}```\n"
end
end
end
end
end