mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-06 17:57:05 +00:00
refactor: releasepr markdown handling
This commit is contained in:
parent
0750bd6b46
commit
94caead6aa
6 changed files with 466 additions and 83 deletions
|
|
@ -7,7 +7,8 @@ import (
|
|||
// A Section struct represents a section of elements.
|
||||
type Section struct {
|
||||
gast.BaseBlock
|
||||
Name string
|
||||
Name string
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// Dump implements Node.Dump.
|
||||
|
|
@ -26,6 +27,10 @@ func (n *Section) Kind() gast.NodeKind {
|
|||
return KindSection
|
||||
}
|
||||
|
||||
func (n *Section) HideInOutput() {
|
||||
n.Hidden = true
|
||||
}
|
||||
|
||||
// NewSection returns a new Section node.
|
||||
func NewSection(name string) *Section {
|
||||
return &Section{Name: name}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ var (
|
|||
|
||||
const (
|
||||
sectionTrigger = "<!--"
|
||||
SectionStartFormat = "<!-- section-start %s -->"
|
||||
SectionEndFormat = "<!-- section-end %s -->"
|
||||
SectionStartFormat = "<!-- section-start %s -->\n"
|
||||
SectionEndFormat = "\n<!-- section-end %s -->"
|
||||
)
|
||||
|
||||
type sectionParser struct{}
|
||||
|
|
@ -91,6 +91,10 @@ func (s SectionMarkdownRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegi
|
|||
func (s SectionMarkdownRenderer) renderSection(w util.BufWriter, _ []byte, node gast.Node, enter bool) (gast.WalkStatus, error) {
|
||||
n := node.(*ast.Section)
|
||||
|
||||
if n.Hidden {
|
||||
return gast.WalkContinue, nil
|
||||
}
|
||||
|
||||
if enter {
|
||||
// Add blank previous line if applicable
|
||||
if node.PreviousSibling() != nil && node.HasBlankPreviousLines() {
|
||||
|
|
@ -107,12 +111,10 @@ func (s SectionMarkdownRenderer) renderSection(w util.BufWriter, _ []byte, node
|
|||
return gast.WalkStop, fmt.Errorf(": %w", err)
|
||||
}
|
||||
|
||||
if _, err := w.WriteRune('\n'); err != nil {
|
||||
return gast.WalkStop, err
|
||||
}
|
||||
}
|
||||
|
||||
return gast.WalkContinue, nil
|
||||
// Somehow the goldmark-markdown renderer does not flush this properly on its own
|
||||
return gast.WalkContinue, w.Flush()
|
||||
}
|
||||
|
||||
type section struct{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue