• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

charmbracelet / glow / 12170497254

04 Dec 2024 11:53PM UTC coverage: 7.821% (-2.7%) from 10.556%
12170497254

Pull #661

github

bashbunni
wip: what is happening in fineGitHubREADME for actions...
Pull Request #661: test: skip networked tests if no connection

4 of 9 new or added lines in 2 files covered. (44.44%)

57 existing lines in 2 files now uncovered.

154 of 1969 relevant lines covered (7.82%)

1.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/utils/utils.go
1
package utils
2

3
import (
4
        "os"
5
        "path/filepath"
6
        "regexp"
7
        "strings"
8

9
        "github.com/charmbracelet/glamour"
10
        "github.com/charmbracelet/glamour/ansi"
11
        "github.com/charmbracelet/glamour/styles"
12
        "github.com/charmbracelet/lipgloss"
13
        "github.com/mitchellh/go-homedir"
14
)
15

16
// RemoveFrontmatter removes the front matter header of a markdown file.
UNCOV
17
func RemoveFrontmatter(content []byte) []byte {
×
UNCOV
18
        if frontmatterBoundaries := detectFrontmatter(content); frontmatterBoundaries[0] == 0 {
×
19
                return content[frontmatterBoundaries[1]:]
×
20
        }
×
UNCOV
21
        return content
×
22
}
23

24
var yamlPattern = regexp.MustCompile(`(?m)^---\r?\n(\s*\r?\n)?`)
25

UNCOV
26
func detectFrontmatter(c []byte) []int {
×
UNCOV
27
        if matches := yamlPattern.FindAllIndex(c, 2); len(matches) > 1 {
×
28
                return []int{matches[0][0], matches[1][1]}
×
29
        }
×
UNCOV
30
        return []int{-1, -1}
×
31
}
32

33
// Expands tilde and all environment variables from the given path.
34
func ExpandPath(path string) string {
×
35
        s, err := homedir.Expand(path)
×
36
        if err == nil {
×
37
                return os.ExpandEnv(s)
×
38
        }
×
39
        return os.ExpandEnv(path)
×
40
}
41

42
// WrapCodeBlock wraps a string in a code block with the given language.
43
func WrapCodeBlock(s, language string) string {
×
44
        return "```" + language + "\n" + s + "```"
×
45
}
×
46

47
var markdownExtensions = []string{
48
        ".md", ".mdown", ".mkdn", ".mkd", ".markdown",
49
}
50

51
// IsMarkdownFile returns whether the filename has a markdown extension.
UNCOV
52
func IsMarkdownFile(filename string) bool {
×
UNCOV
53
        ext := filepath.Ext(filename)
×
UNCOV
54

×
UNCOV
55
        if ext == "" {
×
56
                // By default, assume it's a markdown file.
×
57
                return true
×
58
        }
×
59

UNCOV
60
        for _, v := range markdownExtensions {
×
UNCOV
61
                if strings.EqualFold(ext, v) {
×
UNCOV
62
                        return true
×
UNCOV
63
                }
×
64
        }
65

66
        // Has an extension but not markdown
67
        // so assume this is a code file.
68
        return false
×
69
}
70

UNCOV
71
func GlamourStyle(style string, isCode bool) glamour.TermRendererOption {
×
UNCOV
72
        if !isCode {
×
UNCOV
73
                if style == styles.AutoStyle {
×
UNCOV
74
                        return glamour.WithAutoStyle()
×
UNCOV
75
                } else {
×
76
                        return glamour.WithStylePath(style)
×
77
                }
×
78
        }
79

80
        // If we are rendering a pure code block, we need to modify the style to
81
        // remove the indentation.
82

83
        var styleConfig ansi.StyleConfig
×
84

×
85
        switch style {
×
86
        case styles.AutoStyle:
×
87
                if lipgloss.HasDarkBackground() {
×
88
                        styleConfig = styles.DarkStyleConfig
×
89
                } else {
×
90
                        styleConfig = styles.LightStyleConfig
×
91
                }
×
92
        case styles.DarkStyle:
×
93
                styleConfig = styles.DarkStyleConfig
×
94
        case styles.LightStyle:
×
95
                styleConfig = styles.LightStyleConfig
×
96
        case styles.PinkStyle:
×
97
                styleConfig = styles.PinkStyleConfig
×
98
        case styles.NoTTYStyle:
×
99
                styleConfig = styles.NoTTYStyleConfig
×
100
        case styles.DraculaStyle:
×
101
                styleConfig = styles.DraculaStyleConfig
×
102
        case styles.TokyoNightStyle:
×
103
                styleConfig = styles.DraculaStyleConfig
×
104
        default:
×
105
                return glamour.WithStylesFromJSONFile(style)
×
106
        }
107

108
        var margin uint
×
109
        styleConfig.CodeBlock.Margin = &margin
×
110

×
111
        return glamour.WithStyles(styleConfig)
×
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc