Ai
1 Star 0 Fork 0

studvc/glow-1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.go 740 Bytes
一键复制 编辑 原始数据 按行查看 历史
Nicolas Martin 提交于 2020-12-16 23:23 +08:00 . Expand the path for a specified style file
package utils
import (
"os"
"regexp"
"github.com/mitchellh/go-homedir"
)
func RemoveFrontmatter(content []byte) []byte {
if frontmatterBoundaries := detectFrontmatter(content); frontmatterBoundaries[0] == 0 {
return content[frontmatterBoundaries[1]:]
}
return content
}
var yamlPattern = regexp.MustCompile(`(?m)^---\r?\n(\s*\r?\n)?`)
func detectFrontmatter(c []byte) []int {
if matches := yamlPattern.FindAllIndex(c, 2); len(matches) > 1 {
return []int{matches[0][0], matches[1][1]}
}
return []int{-1, -1}
}
// Expands tilde and all environment variables from the given path.
func ExpandPath(path string) string {
s, err := homedir.Expand(path)
if err == nil {
return os.ExpandEnv(s)
}
return os.ExpandEnv(path)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/studvc/glow-1.git
git@gitee.com:studvc/glow-1.git
studvc
glow-1
glow-1
master

搜索帮助