From 44f94ace7287b4310afd66831f961132546821b1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 15 Dec 2024 20:05:01 +0100 Subject: [PATCH 1/2] Revert "md2man.go: rename ioutil to io" for compat with go <= 1.17 This reverts commit 76076049c2eabc4093673224cdb3dbccd2b5db1d. Signed-off-by: Sebastiaan van Stijn --- md2man.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/md2man.go b/md2man.go index 4ea49f3..4ff873b 100644 --- a/md2man.go +++ b/md2man.go @@ -3,7 +3,7 @@ package main import ( "flag" "fmt" - "io" + "io/ioutil" "os" "github.com/cpuguy83/go-md2man/v2/md2man" @@ -28,7 +28,7 @@ func main() { } defer inFile.Close() // nolint: errcheck - doc, err := io.ReadAll(inFile) + doc, err := ioutil.ReadAll(inFile) if err != nil { fmt.Println(err) os.Exit(1) From 90cf377169b35ee18f1a3ab06b80d0b1bbf8401d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 15 Dec 2024 20:14:33 +0100 Subject: [PATCH 2/2] md2man: use local copy of bytes.Copy for compat with go < 1.17 Signed-off-by: Sebastiaan van Stijn --- md2man/roff.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/md2man/roff.go b/md2man/roff.go index 9d6c473..96a80c9 100644 --- a/md2man/roff.go +++ b/md2man/roff.go @@ -104,7 +104,7 @@ func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering 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(" - ")) + before, after, found := bytesCut(node.Literal, []byte(" - ")) escapeSpecialChars(w, before) if found { out(w, ` \- `) @@ -406,3 +406,12 @@ func escapeSpecialCharsLine(w io.Writer, text []byte) { w.Write([]byte{'\\', text[i]}) // nolint: errcheck } } + +// bytesCut is a copy of [bytes.Cut] to provide compatibility with go1.17 +// and older. We can remove this once we drop support for go1.17 and older. +func bytesCut(s, sep []byte) (before, after []byte, found bool) { + if i := bytes.Index(s, sep); i >= 0 { + return s[:i], s[i+len(sep):], true + } + return s, nil, false +}