Welcome to mirror list, hosted at ThFree Co, Russian Federation.

front_matter.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7612bd36aca15b8134749e5674b40ab0f29a99f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

module Gitlab
  module FrontMatter
    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 block content (not greedy)
      \s*
      ^(\k<delim> | \.{3})                   # closing front matter marker
      \s*
    }mx.freeze
  end
end