fix(deps): update module github.com/cpuguy83/go-md2man/v2 to v2.0.5

Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
renovate[bot] 2024-09-16 18:26:51 +00:00 committed by GitHub
parent 156efe5ded
commit 1a1001d824
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 145 additions and 38 deletions

View File

@ -5,7 +5,7 @@ go 1.22.0
toolchain go1.22.7 toolchain go1.22.7
require ( require (
github.com/cpuguy83/go-md2man/v2 v2.0.4 github.com/cpuguy83/go-md2man/v2 v2.0.5
github.com/go-swagger/go-swagger v0.30.5 github.com/go-swagger/go-swagger v0.30.5
github.com/onsi/ginkgo/v2 v2.20.2 github.com/onsi/ginkgo/v2 v2.20.2
github.com/vbatts/git-validation v1.2.1 github.com/vbatts/git-validation v1.2.1

View File

@ -57,8 +57,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

View File

@ -13,6 +13,18 @@ written purely in Go so as to reduce dependencies on 3rd party libs.
By default, the input is stdin and the output is stdout. By default, the input is stdin and the output is stdout.
# OPTIONS
**-in=**_file_
: Path to markdown file to be processed.
Defaults to stdin.
**-out=**_file_
: Path to output processed file.
Defaults to stdout.
# EXAMPLES # EXAMPLES
Convert the markdown file *go-md2man.1.md* into a manpage: Convert the markdown file *go-md2man.1.md* into a manpage:
``` ```

View File

@ -3,7 +3,7 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io"
"os" "os"
"github.com/cpuguy83/go-md2man/v2/md2man" "github.com/cpuguy83/go-md2man/v2/md2man"
@ -28,7 +28,7 @@ func main() {
} }
defer inFile.Close() // nolint: errcheck defer inFile.Close() // nolint: errcheck
doc, err := ioutil.ReadAll(inFile) doc, err := io.ReadAll(inFile)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)

View File

@ -0,0 +1,62 @@
package md2man
import (
"fmt"
"io"
"os"
"strings"
"github.com/russross/blackfriday/v2"
)
func fmtListFlags(flags blackfriday.ListType) string {
knownFlags := []struct {
name string
flag blackfriday.ListType
}{
{"ListTypeOrdered", blackfriday.ListTypeOrdered},
{"ListTypeDefinition", blackfriday.ListTypeDefinition},
{"ListTypeTerm", blackfriday.ListTypeTerm},
{"ListItemContainsBlock", blackfriday.ListItemContainsBlock},
{"ListItemBeginningOfList", blackfriday.ListItemBeginningOfList},
{"ListItemEndOfList", blackfriday.ListItemEndOfList},
}
var f []string
for _, kf := range knownFlags {
if flags&kf.flag != 0 {
f = append(f, kf.name)
flags &^= kf.flag
}
}
if flags != 0 {
f = append(f, fmt.Sprintf("Unknown(%#x)", flags))
}
return strings.Join(f, "|")
}
type debugDecorator struct {
blackfriday.Renderer
}
func depth(node *blackfriday.Node) int {
d := 0
for n := node.Parent; n != nil; n = n.Parent {
d++
}
return d
}
func (d *debugDecorator) RenderNode(w io.Writer, node *blackfriday.Node, entering bool) blackfriday.WalkStatus {
fmt.Fprintf(os.Stderr, "%s%s %v %v\n",
strings.Repeat(" ", depth(node)),
map[bool]string{true: "+", false: "-"}[entering],
node,
fmtListFlags(node.ListFlags))
var b strings.Builder
status := d.Renderer.RenderNode(io.MultiWriter(&b, w), node, entering)
if b.Len() > 0 {
fmt.Fprintf(os.Stderr, ">> %q\n", b.String())
}
return status
}

View File

@ -1,16 +1,23 @@
package md2man package md2man
import ( import (
"os"
"strconv"
"github.com/russross/blackfriday/v2" "github.com/russross/blackfriday/v2"
) )
// Render converts a markdown document into a roff formatted document. // Render converts a markdown document into a roff formatted document.
func Render(doc []byte) []byte { func Render(doc []byte) []byte {
renderer := NewRoffRenderer() renderer := NewRoffRenderer()
var r blackfriday.Renderer = renderer
if v, _ := strconv.ParseBool(os.Getenv("MD2MAN_DEBUG")); v {
r = &debugDecorator{Renderer: r}
}
return blackfriday.Run(doc, return blackfriday.Run(doc,
[]blackfriday.Option{ []blackfriday.Option{
blackfriday.WithRenderer(renderer), blackfriday.WithRenderer(r),
blackfriday.WithExtensions(renderer.GetExtensions()), blackfriday.WithExtensions(renderer.GetExtensions()),
}...) }...)
} }

View File

@ -14,10 +14,8 @@ import (
// roffRenderer implements the blackfriday.Renderer interface for creating // roffRenderer implements the blackfriday.Renderer interface for creating
// roff format (manpages) from markdown text // roff format (manpages) from markdown text
type roffRenderer struct { type roffRenderer struct {
extensions blackfriday.Extensions
listCounters []int listCounters []int
firstHeader bool firstHeader bool
firstDD bool
listDepth int listDepth int
} }
@ -43,7 +41,7 @@ const (
quoteTag = "\n.PP\n.RS\n" quoteTag = "\n.PP\n.RS\n"
quoteCloseTag = "\n.RE\n" quoteCloseTag = "\n.RE\n"
listTag = "\n.RS\n" listTag = "\n.RS\n"
listCloseTag = "\n.RE\n" listCloseTag = ".RE\n"
dtTag = "\n.TP\n" dtTag = "\n.TP\n"
dd2Tag = "\n" dd2Tag = "\n"
tableStart = "\n.TS\nallbox;\n" tableStart = "\n.TS\nallbox;\n"
@ -56,23 +54,18 @@ const (
// NewRoffRenderer creates a new blackfriday Renderer for generating roff documents // NewRoffRenderer creates a new blackfriday Renderer for generating roff documents
// from markdown // from markdown
func NewRoffRenderer() *roffRenderer { // nolint: golint func NewRoffRenderer() *roffRenderer { // nolint: golint
var extensions blackfriday.Extensions return &roffRenderer{}
extensions |= blackfriday.NoIntraEmphasis
extensions |= blackfriday.Tables
extensions |= blackfriday.FencedCode
extensions |= blackfriday.SpaceHeadings
extensions |= blackfriday.Footnotes
extensions |= blackfriday.Titleblock
extensions |= blackfriday.DefinitionLists
return &roffRenderer{
extensions: extensions,
}
} }
// GetExtensions returns the list of extensions used by this renderer implementation // GetExtensions returns the list of extensions used by this renderer implementation
func (r *roffRenderer) GetExtensions() blackfriday.Extensions { func (*roffRenderer) GetExtensions() blackfriday.Extensions {
return r.extensions return blackfriday.NoIntraEmphasis |
blackfriday.Tables |
blackfriday.FencedCode |
blackfriday.SpaceHeadings |
blackfriday.Footnotes |
blackfriday.Titleblock |
blackfriday.DefinitionLists
} }
// RenderHeader handles outputting the header at document start // RenderHeader handles outputting the header at document start
@ -103,7 +96,23 @@ func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering
switch node.Type { switch node.Type {
case blackfriday.Text: case blackfriday.Text:
escapeSpecialChars(w, node.Literal) // Special case: format the NAME section as required for proper whatis parsing.
// Refer to the lexgrog(1) and groff_man(7) manual pages for details.
if node.Parent != nil &&
node.Parent.Type == blackfriday.Paragraph &&
node.Parent.Prev != nil &&
node.Parent.Prev.Type == blackfriday.Heading &&
node.Parent.Prev.FirstChild != nil &&
bytes.EqualFold(node.Parent.Prev.FirstChild.Literal, []byte("NAME")) {
before, after, found := bytes.Cut(node.Literal, []byte(" - "))
escapeSpecialChars(w, before)
if found {
out(w, ` \- `)
escapeSpecialChars(w, after)
}
} else {
escapeSpecialChars(w, node.Literal)
}
case blackfriday.Softbreak: case blackfriday.Softbreak:
out(w, crTag) out(w, crTag)
case blackfriday.Hardbreak: case blackfriday.Hardbreak:
@ -141,14 +150,25 @@ func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering
case blackfriday.Document: case blackfriday.Document:
break break
case blackfriday.Paragraph: case blackfriday.Paragraph:
// roff .PP markers break lists
if r.listDepth > 0 {
return blackfriday.GoToNext
}
if entering { if entering {
out(w, paraTag) if r.listDepth > 0 {
// roff .PP markers break lists
if node.Prev != nil { // continued paragraph
if node.Prev.Type == blackfriday.List && node.Prev.ListFlags&blackfriday.ListTypeDefinition == 0 {
out(w, ".IP\n")
} else {
out(w, crTag)
}
}
} else if node.Prev != nil && node.Prev.Type == blackfriday.Heading {
out(w, crTag)
} else {
out(w, paraTag)
}
} else { } else {
out(w, crTag) if node.Next == nil || node.Next.Type != blackfriday.List {
out(w, crTag)
}
} }
case blackfriday.BlockQuote: case blackfriday.BlockQuote:
if entering { if entering {
@ -211,6 +231,10 @@ func (r *roffRenderer) handleHeading(w io.Writer, node *blackfriday.Node, enteri
func (r *roffRenderer) handleList(w io.Writer, node *blackfriday.Node, entering bool) { func (r *roffRenderer) handleList(w io.Writer, node *blackfriday.Node, entering bool) {
openTag := listTag openTag := listTag
closeTag := listCloseTag closeTag := listCloseTag
if (entering && r.listDepth == 0) || (!entering && r.listDepth == 1) {
openTag = crTag
closeTag = ""
}
if node.ListFlags&blackfriday.ListTypeDefinition != 0 { if node.ListFlags&blackfriday.ListTypeDefinition != 0 {
// tags for definition lists handled within Item node // tags for definition lists handled within Item node
openTag = "" openTag = ""
@ -239,23 +263,25 @@ func (r *roffRenderer) handleItem(w io.Writer, node *blackfriday.Node, entering
} else if node.ListFlags&blackfriday.ListTypeTerm != 0 { } else if node.ListFlags&blackfriday.ListTypeTerm != 0 {
// DT (definition term): line just before DD (see below). // DT (definition term): line just before DD (see below).
out(w, dtTag) out(w, dtTag)
r.firstDD = true
} else if node.ListFlags&blackfriday.ListTypeDefinition != 0 { } else if node.ListFlags&blackfriday.ListTypeDefinition != 0 {
// DD (definition description): line that starts with ": ". // DD (definition description): line that starts with ": ".
// //
// We have to distinguish between the first DD and the // We have to distinguish between the first DD and the
// subsequent ones, as there should be no vertical // subsequent ones, as there should be no vertical
// whitespace between the DT and the first DD. // whitespace between the DT and the first DD.
if r.firstDD { if node.Prev != nil && node.Prev.ListFlags&(blackfriday.ListTypeTerm|blackfriday.ListTypeDefinition) == blackfriday.ListTypeDefinition {
r.firstDD = false if node.Prev.Type == blackfriday.Item &&
} else { node.Prev.LastChild != nil &&
out(w, dd2Tag) node.Prev.LastChild.Type == blackfriday.List &&
node.Prev.LastChild.ListFlags&blackfriday.ListTypeDefinition == 0 {
out(w, ".IP\n")
} else {
out(w, dd2Tag)
}
} }
} else { } else {
out(w, ".IP \\(bu 2\n") out(w, ".IP \\(bu 2\n")
} }
} else {
out(w, "\n")
} }
} }

View File

@ -10,7 +10,7 @@ github.com/Masterminds/sprig/v3
# github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 # github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
## explicit; go 1.13 ## explicit; go 1.13
github.com/asaskevich/govalidator github.com/asaskevich/govalidator
# github.com/cpuguy83/go-md2man/v2 v2.0.4 # github.com/cpuguy83/go-md2man/v2 v2.0.5
## explicit; go 1.11 ## explicit; go 1.11
github.com/cpuguy83/go-md2man/v2 github.com/cpuguy83/go-md2man/v2
github.com/cpuguy83/go-md2man/v2/md2man github.com/cpuguy83/go-md2man/v2/md2man