Class: Banzai::Filter::YamlFrontMatterFilter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Defined in:
lib/banzai/filter/yaml_front_matter_filter.rb

Constant Summary collapse

DELIM =
'---'.freeze
PATTERN =

Hat-tip to Middleman: git.io/v2e0z

%r{
  \A(?:[^\r\n]*coding:[^\r\n]*\r?\n)?
  (?<start>#{DELIM})[ ]*\r?\n
  (?<frontmatter>.*?)[ ]*\r?\n?
  ^(?<stop>#{DELIM})[ ]*\r?\n?
  \r?\n?
  (?<content>.*)
}mx.freeze

Instance Method Summary collapse

Instance Method Details

#callObject


16
17
18
19
20
21
22
# File 'lib/banzai/filter/yaml_front_matter_filter.rb', line 16

def call
  match = PATTERN.match(html)

  return html unless match

  "```yaml\n#{match['frontmatter']}\n```\n\n#{match['content']}"
end