Skip to content

Commit

Permalink
chore: replace CR LF \r\n (windows) with LF \n (unix) and replace CF …
Browse files Browse the repository at this point in the history
…\r (mac) with LF \n (unix)
  • Loading branch information
ystyle committed Sep 6, 2022
1 parent 4a4a592 commit e7a3bf1
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 11 deletions.
2 changes: 1 addition & 1 deletion embed_markdown_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (mdd *EmbedMarkdownDriver) parseMarkdown(filename string) ([]SqlTemple, err
return nil, err
}
if bytes.ContainsRune(buf, '\r') {
buf = NormalizeNewlines(buf)
buf = markdown.NormalizeNewlines(buf)
}
psr := parser.New()
node := markdown.Parse(buf, psr)
Expand Down
2 changes: 1 addition & 1 deletion file_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func parseMarkdown(filename string) ([]SqlTemple, error) {
return nil, err
}
if bytes.ContainsRune(buf, '\r') {
buf = NormalizeNewlines(buf)
buf = markdown.NormalizeNewlines(buf)
}
psr := parser.New()
node := markdown.Parse(bytes.ReplaceAll(buf, []byte("\r"), nil), psr)
Expand Down
9 changes: 0 additions & 9 deletions markdown.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sqlmanager

import (
"bytes"
"github.com/gomarkdown/markdown/ast"
)

Expand All @@ -24,11 +23,3 @@ func getAll(node ast.Node) []item {
})
return list
}

func NormalizeNewlines(d []byte) []byte {
// replace CR LF \r\n (windows) with LF \n (unix)
d = bytes.Replace(d, []byte{13, 10}, []byte{10}, -1)
// replace CF \r (mac) with LF \n (unix)
d = bytes.Replace(d, []byte{13}, []byte{10}, -1)
return d
}

0 comments on commit e7a3bf1

Please sign in to comment.