summaryrefslogtreecommitdiffstats
path: root/parser
diff options
context:
space:
mode:
authorVas Sudanagunta <vas@commonkarma.org>2018-02-11 19:10:49 -0500
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-02-12 17:14:40 +0100
commit1fa2417777d82b81bf37919ad02de4f5dcbf0d50 (patch)
tree32ea28c273e8f0c66fcaec1df6a7bf3b3a643a31 /parser
parentbb549a0d57505a6b8f28930bb91a9ab44cbb3288 (diff)
Add support for YAML array data files
* Unmarshaled YAML arrays indistinguishable from JSON arrays. * Fixes #3890
Diffstat (limited to 'parser')
-rw-r--r--parser/frontmatter.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/parser/frontmatter.go b/parser/frontmatter.go
index c1a57ce5b..5ed3ec11d 100644
--- a/parser/frontmatter.go
+++ b/parser/frontmatter.go
@@ -216,6 +216,23 @@ func HandleYAMLMetaData(datum []byte) (map[string]interface{}, error) {
return m, err
}
+// HandleYAMLData unmarshals YAML-encoded datum and returns a Go interface
+// representing the encoded data structure.
+func HandleYAMLData(datum []byte) (interface{}, error) {
+ var m interface{}
+ err := yaml.Unmarshal(datum, &m)
+
+ // To support boolean keys, the `yaml` package unmarshals maps to
+ // map[interface{}]interface{}. Here we recurse through the result
+ // and change all maps to map[string]interface{} like we would've
+ // gotten from `json`.
+ if err == nil {
+ m = stringifyYAMLMapKeys(m)
+ }
+
+ return m, err
+}
+
// stringifyKeysMapValue recurses into in and changes all instances of
// map[interface{}]interface{} to map[string]interface{}. This is useful to
// work around the impedence mismatch between JSON and YAML unmarshaling that's