rewrite some frontmatter and editor-related stuff

Former-commit-id: 15e46f99c745757eab86f329caebd3bba102f4dc
This commit is contained in:
Henrique Dias
2017-01-18 18:40:20 +00:00
parent 34ce7afb88
commit 0ad540249e
5 changed files with 51 additions and 37 deletions

View File

@@ -2,6 +2,7 @@ package frontmatter
import (
"bytes"
"errors"
"strings"
)
@@ -28,28 +29,30 @@ func AppendRune(frontmatter []byte, mark rune) []byte {
return frontmatter
}
func RuneToStringFormat(mark rune) string {
// RuneToStringFormat converts the rune to a string with the format
func RuneToStringFormat(mark rune) (string, error) {
switch mark {
case '-':
return "yaml"
return "yaml", nil
case '+':
return "toml"
return "toml", nil
case '{':
return "json"
return "json", nil
default:
return ""
return "", errors.New("Unsupported format type.")
}
}
func StringFormatToRune(format string) rune {
// StringFormatToRune converts the format name to its rune
func StringFormatToRune(format string) (rune, error) {
switch format {
case "yaml":
return '-'
return '-', nil
case "toml":
return '+'
return '+', nil
case "json":
return '{'
return '{', nil
default:
return '0'
return '0', errors.New("Unsupported format type.")
}
}