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

yuin / goldmark / 41005688715

30 Oct 2026 04:53AM UTC coverage: 82.356% (-0.1%) from 82.492%
41005688715

push

github

yuin
chore: bump golangci-lint to v2

5 of 5 new or added lines in 2 files covered. (100.0%)

129 existing lines in 7 files now uncovered.

6306 of 7657 relevant lines covered (82.36%)

465742.65 hits per line

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

95.52
/parser/code_block.go
1
package parser
2

3
import (
4
        "github.com/yuin/goldmark/ast"
5
        "github.com/yuin/goldmark/text"
6
        "github.com/yuin/goldmark/util"
7
)
8

9
type codeBlockParser struct {
10
}
11

12
// CodeBlockParser is a BlockParser implementation that parses indented code blocks.
13
var defaultCodeBlockParser = &codeBlockParser{}
14

15
// NewCodeBlockParser returns a new BlockParser that
16
// parses code blocks.
17
func NewCodeBlockParser() BlockParser {
2,148 ✔
18
        return defaultCodeBlockParser
2,148 ✔
19
}
2,148 ✔
20

21
func (b *codeBlockParser) Trigger() []byte {
2,136 ✔
22
        return nil
2,136 ✔
23
}
2,136 ✔
24

25
func (b *codeBlockParser) Open(parent ast.Node, reader text.Reader, pc Context) (ast.Node, State) {
5,880 ✔
26
        line, segment := reader.PeekLine()
5,880 ✔
27
        pos, padding := util.IndentPositionPadding(line, reader.LineOffset(), segment.Padding, 4)
5,880 ✔
28
        if pos < 0 || util.IsBlank(line) {
11,379 ✔
29
                return nil, NoChildren
5,499 ✔
30
        }
5,499 ✔
31
        node := ast.NewCodeBlock()
381 ✔
32
        segment = text.NewSegmentPadding(segment.Start+pos, segment.Stop, padding)
381 ✔
33
        // if code block line starts with a tab, keep a tab as it is.
381 ✔
34
        if segment.Padding != 0 {
399 ✔
35
                preserveLeadingTabInCodeBlock(&segment, reader, 0)
18 ✔
36
        }
18 ✔
37
        segment.ForceNewline = true
381 ✔
38
        node.Lines().Append(segment)
381 ✔
39
        reader.AdvanceToEOL()
381 ✔
40
        return node, NoChildren
381 ✔
41

42
}
43

44
func (b *codeBlockParser) Continue(node ast.Node, reader text.Reader, pc Context) State {
540 ✔
45
        line, segment := reader.PeekLine()
540 ✔
46
        pos, padding := util.IndentPositionPadding(line, reader.LineOffset(), segment.Padding, 4)
540 ✔
47

540 ✔
48
        if util.IsBlank(line) && pos < 0 {
708 ✔
49
                segment = text.NewSegment(segment.Stop-1, segment.Stop)
168 ✔
50
        } else if pos < 0 {
675 ✔
51
                return Close
135 ✔
52
        } else {
372 ✔
53
                segment = text.NewSegmentPadding(segment.Start+pos, segment.Stop, padding)
237 ✔
54
                segment.ForceNewline = true
237 ✔
55
                // if code block line starts with a tab, keep a tab as it is.
237 ✔
56
                if segment.Padding != 0 {
246 ✔
57
                        preserveLeadingTabInCodeBlock(&segment, reader, 0)
9 ✔
58
                }
9 ✔
59
        }
60
        node.Lines().Append(segment)
405 ✔
61
        reader.AdvanceToEOL()
405 ✔
62
        return Continue | NoChildren
405 ✔
63
}
64

65
func (b *codeBlockParser) Close(node ast.Node, reader text.Reader, pc Context) {
381 ✔
66
        // trim trailing blank lines
381 ✔
67
        lines := node.Lines()
381 ✔
68
        length := lines.Len() - 1
381 ✔
69
        source := reader.Source()
381 ✔
70
        for length >= 0 {
876 ✔
71
                line := lines.At(length)
495 ✔
72
                if util.IsBlank(line.Value(source)) {
609 ✔
73
                        length--
114 ✔
74
                } else {
495 ✔
75
                        break
381 ✔
76
                }
77
        }
78
        lines.SetSliced(0, length+1)
381 ✔
79
}
80

81
func (b *codeBlockParser) CanInterruptParagraph() bool {
1,233 ✔
82
        return false
1,233 ✔
83
}
1,233 ✔
84

85
func (b *codeBlockParser) CanAcceptIndentedLine() bool {
381 ✔
86
        return true
381 ✔
87
}
381 ✔
88

89
func preserveLeadingTabInCodeBlock(segment *text.Segment, reader text.Reader, indent int) {
36 ✔
90
        offsetWithPadding := reader.LineOffset() + indent
36 ✔
91
        sl, ss := reader.Position()
36 ✔
92
        reader.SetPosition(sl, text.NewSegment(ss.Start-1, ss.Stop))
36 ✔
93
        if offsetWithPadding == reader.LineOffset() {
36 ✔
UNCOV
94
                segment.Padding = 0
×
UNCOV
95
                segment.Start--
×
UNCOV
96
        }
×
97
        reader.SetPosition(sl, ss)
36 ✔
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc