Sha256: 36d5714509ee86a69f2cf5db86f84fff75b056db50f10a62d44fbd540705e68a

Contents?: true

Size: 1.02 KB

Versions: 6

Compression:

Stored size: 1.02 KB

Contents

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

  def process(d)
    d
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gollum-lib-4.0.3-java lib/gollum-lib/filter/metadata.rb
gollum-lib-4.0.3 lib/gollum-lib/filter/metadata.rb
gollum-lib-4.0.2 lib/gollum-lib/filter/metadata.rb
gollum-lib-4.0.1 lib/gollum-lib/filter/metadata.rb
gollum-lib-4.0.0 lib/gollum-lib/filter/metadata.rb
gollum-lib-3.0.0 lib/gollum-lib/filter/metadata.rb