diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-15 03:09:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-15 03:09:11 +0000 |
commit | b71a496c7a3e109f7c85ad7ac453e6f7bf7cda45 (patch) | |
tree | 0a76fc00ef860bd369dcaa3f136ee36275eb47f5 /lib/banzai | |
parent | c2041156b8b3063d6cf29b324416e8469e588923 (diff) | |
download | gitlab-ce-b71a496c7a3e109f7c85ad7ac453e6f7bf7cda45.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/filter/front_matter_filter.rb | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/lib/banzai/filter/front_matter_filter.rb b/lib/banzai/filter/front_matter_filter.rb index 544231adea4..5900e762244 100644 --- a/lib/banzai/filter/front_matter_filter.rb +++ b/lib/banzai/filter/front_matter_filter.rb @@ -3,28 +3,11 @@ module Banzai module Filter class FrontMatterFilter < HTML::Pipeline::Filter - DELIM_LANG = { - '---' => 'yaml', - '+++' => 'toml', - ';;;' => 'json' - }.freeze - - DELIM = Regexp.union(DELIM_LANG.keys) - - PATTERN = %r{ - \A(?:[^\r\n]*coding:[^\r\n]*)? # optional encoding line - \s* - ^(?<delim>#{DELIM})[ \t]*(?<lang>\S*) # opening front matter marker (optional language specifier) - \s* - ^(?<front_matter>.*?) # front matter (not greedy) - \s* - ^\k<delim> # closing front matter marker - \s* - }mx.freeze - def call - html.sub(PATTERN) do |_match| - lang = $~[:lang].presence || DELIM_LANG[$~[:delim]] + 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 |