lib/gollum-lib/markup.rb in gollum-lib-1.0.3 vs lib/gollum-lib/markup.rb in gollum-lib-1.0.4
- old
+ new
@@ -648,22 +648,33 @@
#
# Metadata
#
#########################################################################
- # Extract metadata for data and build metadata table. Metadata
- # is content found between markers, and must
- # be a valid YAML mapping.
+ # 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
#
# Returns the String of formatted data with metadata removed.
def extract_metadata(data)
- @metadata = {}
- data
+ @metadata ||= {}
+ # The markers are `<!-- ---` and `-->`
+ data.gsub(/\<\!--+\s+---(.*?)--+\>/m) do
+ # 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)
+ @metadata[k.strip] = (v ? v.strip : '') if k
+ end
+ ''
+ end
end
# Hook for getting the formatted value of extracted tag data.
#
# type - Symbol value identifying what type of data is being extracted.