Skip to content

Commit

Permalink
Merge pull request #130 from thaJeztah/keep_go111_compat
Browse files Browse the repository at this point in the history
Preserve compatibility with go <= 1.17
  • Loading branch information
cpuguy83 authored Dec 16, 2024
2 parents bb5af6e + 90cf377 commit ae728a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions md2man.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/cpuguy83/go-md2man/v2/md2man"
Expand All @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion md2man/roff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ` \- `)
Expand Down Expand Up @@ -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
}

0 comments on commit ae728a9

Please sign in to comment.