Sha256: 896c6cc450a8323e9a8ec175eca6c4fb2d2bac6eb7e63978dfb9e9aebb6c737d

Contents?: true

Size: 824 Bytes

Versions: 11

Compression:

Stored size: 824 Bytes

Contents

require 'yaml'
# Extract YAML frontmatter from data and build metadata table. 

class Gollum::Filter::YAML < Gollum::Filter
  
  # Regexp thanks to jekyll
  YAML_FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m

  def extract(data)
    data.gsub!(YAML_FRONT_MATTER_REGEXP) do
      @markup.metadata ||= {}
      begin
        frontmatter = ::YAML.safe_load(sanitize(Regexp.last_match[1]))
        @markup.metadata.merge!(frontmatter) if frontmatter.respond_to?(:keys) && frontmatter.respond_to?(:values)
      rescue ::Psych::SyntaxError, ::Psych::DisallowedClass, ::Psych::BadAlias => error
        @markup.metadata['errors'] ||= []
        @markup.metadata['errors'] << "Failed to load YAML frontmater: #{error.message}"
      end
      ''
    end
    data
  end

  def process(data)
    data
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
gollum-lib-5.0.5-java lib/gollum-lib/filter/yaml.rb
gollum-lib-5.0.5 lib/gollum-lib/filter/yaml.rb
gollum-lib-5.0.4-java lib/gollum-lib/filter/yaml.rb
gollum-lib-5.0.4 lib/gollum-lib/filter/yaml.rb
gollum-lib-5.0.3-java lib/gollum-lib/filter/yaml.rb
gollum-lib-5.0.3 lib/gollum-lib/filter/yaml.rb
gollum-lib-5.0.2-java lib/gollum-lib/filter/yaml.rb
gollum-lib-5.0.2 lib/gollum-lib/filter/yaml.rb
gollum-lib-5.0.1-java lib/gollum-lib/filter/yaml.rb
gollum-lib-5.0.1 lib/gollum-lib/filter/yaml.rb
gollum-lib-5.0 lib/gollum-lib/filter/yaml.rb