2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Banzai
|
|
|
|
module Filter
|
|
|
|
class FrontMatterFilter < HTML::Pipeline::Filter
|
|
|
|
def call
|
2020-04-22 19:07:51 +05:30
|
|
|
lang_mapping = Gitlab::FrontMatter::DELIM_LANG
|
|
|
|
|
|
|
|
html.sub(Gitlab::FrontMatter::PATTERN) do |_match|
|
|
|
|
lang = $~[:lang].presence || lang_mapping[$~[:delim]]
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
["```#{lang}", $~[:front_matter], "```", "\n"].join("\n")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|