Class: Gollum::Filter::Metadata

Inherits:
Gollum::Filter show all
Defined in:
lib/gollum-lib/filter/metadata.rb

Overview

Extract metadata for data and build metadata table. Metadata consists of key/value pairs in “key:value” format found between markers. Each key/value pair must be on its own line. Internal whitespace in keys and values is preserved, but external whitespace is ignored.

Because ri and ruby 1.8.7 are awesome, the markers can’t be included in this documentation without triggering ‘Unhandled special: Special: type=17` Please read the source code for the exact markers

Instance Method Summary collapse

Methods inherited from Gollum::Filter

#initialize

Methods included from Helpers

#trim_leading_slash

Constructor Details

This class inherits a constructor from Gollum::Filter

Instance Method Details

#extract(data) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gollum-lib/filter/metadata.rb', line 11

def extract(data)
  # The markers are `<!-- ---` and `-->`
  data.gsub(/\<\!--+\s+---(.*?)--+\>/m) do
    @markup. ||= {}
    # Split untrusted input on newlines, then remove bits that look like
    # HTML elements before parsing each line.
    Regexp.last_match[1].split("\n").each do |line|
      line.gsub!(/<[^>]*>/, '')
      k, v                      = line.split(':', 2)
      @markup.[k.strip] = (v ? v.strip : '') if k
    end
    ''
  end
end

#process(data) ⇒ Object



26
27
28
# File 'lib/gollum-lib/filter/metadata.rb', line 26

def process(data)
  data
end