summaryrefslogtreecommitdiffstats
path: root/parser/metadecoders/format.go
diff options
context:
space:
mode:
Diffstat (limited to 'parser/metadecoders/format.go')
-rw-r--r--parser/metadecoders/format.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/parser/metadecoders/format.go b/parser/metadecoders/format.go
index 4a30898fe..719fbf100 100644
--- a/parser/metadecoders/format.go
+++ b/parser/metadecoders/format.go
@@ -31,6 +31,7 @@ const (
JSON Format = "json"
TOML Format = "toml"
YAML Format = "yaml"
+ CSV Format = "csv"
)
// FormatFromString turns formatStr, typically a file extension without any ".",
@@ -51,6 +52,8 @@ func FormatFromString(formatStr string) Format {
return TOML
case "org":
return ORG
+ case "csv":
+ return CSV
}
return ""
@@ -88,11 +91,16 @@ func FormatFromFrontMatterType(typ pageparser.ItemType) Format {
// FormatFromContentString tries to detect the format (JSON, YAML or TOML)
// in the given string.
// It return an empty string if no format could be detected.
-func FormatFromContentString(data string) Format {
+func (d Decoder) FormatFromContentString(data string) Format {
+ csvIdx := strings.IndexRune(data, d.Comma)
jsonIdx := strings.Index(data, "{")
yamlIdx := strings.Index(data, ":")
tomlIdx := strings.Index(data, "=")
+ if isLowerIndexThan(csvIdx, jsonIdx, yamlIdx, tomlIdx) {
+ return CSV
+ }
+
if isLowerIndexThan(jsonIdx, yamlIdx, tomlIdx) {
return JSON
}