debian-mirror-gitlab/lib/gitlab/front_matter.rb

23 lines
641 B
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
module Gitlab
module FrontMatter
DELIM_LANG = {
'---' => 'yaml',
'+++' => 'toml',
';;;' => 'json'
}.freeze
DELIM = Regexp.union(DELIM_LANG.keys)
PATTERN = %r{
2022-05-07 20:08:51 +05:30
\A(?<encoding>[^\r\n]*coding:[^\r\n]*\R)? # optional encoding line
(?<before>\s*)
2021-12-07 22:27:20 +05:30
^(?<delim>#{DELIM})[ \t]*(?<lang>\S*)\R # opening front matter marker (optional language specifier)
(?<front_matter>.*?) # front matter block content (not greedy)
^(\k<delim> | \.{3}) # closing front matter marker
2022-05-07 20:08:51 +05:30
[^\S\r\n]*(\R|\z)
2020-04-22 19:07:51 +05:30
}mx.freeze
end
end