diff --git a/internal/frontmatter/frontmatter.go b/internal/frontmatter/frontmatter.go index 1ad3625..47a245b 100644 --- a/internal/frontmatter/frontmatter.go +++ b/internal/frontmatter/frontmatter.go @@ -2,6 +2,7 @@ package frontmatter import ( "fmt" + "runtime" "strings" "gopkg.in/yaml.v1" @@ -16,15 +17,21 @@ type Frontmatter struct { // Parse parses cheatsheet frontmatter func Parse(markdown string) (string, Frontmatter, error) { + // determine the appropriate line-break for the platform + linebreak := "\n" + if runtime.GOOS == "windows" { + linebreak = "\r\n" + } + // specify the frontmatter delimiter - delim := "---" + delim := fmt.Sprintf("---%s", linebreak) // initialize a frontmatter struct var fm Frontmatter // if the markdown does not contain frontmatter, pass it through unmodified if !strings.HasPrefix(markdown, delim) { - return strings.TrimSpace(markdown), fm, nil + return markdown, fm, nil } // otherwise, split the frontmatter and cheatsheet text @@ -40,5 +47,5 @@ func Parse(markdown string) (string, Frontmatter, error) { return markdown, fm, fmt.Errorf("failed to unmarshal frontmatter: %v", err) } - return strings.TrimSpace(parts[2]), fm, nil + return parts[2], fm, nil } diff --git a/internal/sheet/sheet.go b/internal/sheet/sheet.go index aaf9d92..ece0f50 100644 --- a/internal/sheet/sheet.go +++ b/internal/sheet/sheet.go @@ -51,7 +51,7 @@ func New( Title: title, CheatPath: cheatpath, Path: path, - Text: text + "\n", + Text: text, Tags: tags, Syntax: fm.Syntax, ReadOnly: readOnly,