2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 03:18:55 +00:00

Update vendored library github.com/cpuguy83/go-md2man

This commit is contained in:
Alexander Neumann 2018-03-30 11:48:16 +02:00
parent 673f0bbd6c
commit 30110fcfc2
11 changed files with 104 additions and 42 deletions

4
Gopkg.lock generated
View File

@ -34,8 +34,8 @@
[[projects]]
name = "github.com/cpuguy83/go-md2man"
packages = ["md2man"]
revision = "1d903dcb749992f3741d744c0f8376b4bd7eb3e1"
version = "v1.0.7"
revision = "20f5889cbdc3c73dbd2862796665e7c465ade7d1"
version = "v1.0.8"
[[projects]]
name = "github.com/dgrijalva/jwt-go"

View File

@ -0,0 +1,20 @@
{
"Vendor": true,
"Deadline": "2m",
"Sort": ["linter", "severity", "path", "line"],
"Enable": [
"deadcode",
"errcheck",
"structcheck",
"unused",
"varcheck",
"unconvert",
"gofmt",
"goimports",
"golint",
"ineffassign",
"vet",
"goconst",
"megacheck"
]
}

13
vendor/github.com/cpuguy83/go-md2man/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,13 @@
language: go
go:
- 1.x
- 1.8.x
- 1.9.x
- tip
script:
- script/setup/dev-tools
- script/validate/vendor
- go build -i .
- make check
- go build
- go test -v ./...

2
vendor/github.com/cpuguy83/go-md2man/Makefile generated vendored Normal file
View File

@ -0,0 +1,2 @@
check:
gometalinter --config .gometalinter.json ./...

View File

@ -12,7 +12,10 @@ Uses blackfriday to process markdown into man pages.
### How to contribute
We use [govend](https://github.com/govend/govend) for vendoring Go packages.
We use [dep](https://github.com/golang/dep/) for vendoring Go packages.
See dep documentation for how to update.
How to update dependencies: `govend -v -u --prune`
### TODO
- Needs oh so much testing love
- Look into blackfriday's 2.0 API

View File

@ -24,7 +24,7 @@ func main() {
os.Exit(1)
}
}
defer inFile.Close()
defer inFile.Close() // nolint: errcheck
doc, err := ioutil.ReadAll(inFile)
if err != nil {
@ -41,7 +41,7 @@ func main() {
fmt.Println(err)
os.Exit(1)
}
defer outFile.Close()
defer outFile.Close() // nolint: errcheck
}
_, err = outFile.Write(out)
if err != nil {

View File

@ -4,6 +4,7 @@ import (
"github.com/russross/blackfriday"
)
// Render converts a markdown document into a roff formatted document.
func Render(doc []byte) []byte {
renderer := RoffRenderer(0)
extensions := 0

View File

@ -9,10 +9,12 @@ import (
"github.com/russross/blackfriday"
)
type roffRenderer struct{}
var listCounter int
type roffRenderer struct {
ListCounters []int
}
// RoffRenderer creates a new blackfriday Renderer for generating roff documents
// from markdown
func RoffRenderer(flags int) blackfriday.Renderer {
return &roffRenderer{}
}
@ -55,7 +57,7 @@ func (r *roffRenderer) BlockQuote(out *bytes.Buffer, text []byte) {
out.WriteString("\n.RE\n")
}
func (r *roffRenderer) BlockHtml(out *bytes.Buffer, text []byte) {
func (r *roffRenderer) BlockHtml(out *bytes.Buffer, text []byte) { // nolint: golint
out.Write(text)
}
@ -86,19 +88,20 @@ func (r *roffRenderer) HRule(out *bytes.Buffer) {
func (r *roffRenderer) List(out *bytes.Buffer, text func() bool, flags int) {
marker := out.Len()
if flags&blackfriday.LIST_TYPE_ORDERED != 0 {
listCounter = 1
}
r.ListCounters = append(r.ListCounters, 1)
out.WriteString("\n.RS\n")
if !text() {
out.Truncate(marker)
return
}
r.ListCounters = r.ListCounters[:len(r.ListCounters)-1]
out.WriteString("\n.RE\n")
}
func (r *roffRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
if flags&blackfriday.LIST_TYPE_ORDERED != 0 {
out.WriteString(fmt.Sprintf(".IP \"%3d.\" 5\n", listCounter))
listCounter += 1
out.WriteString(fmt.Sprintf(".IP \"%3d.\" 5\n", r.ListCounters[len(r.ListCounters)-1]))
r.ListCounters[len(r.ListCounters)-1]++
} else {
out.WriteString(".IP \\(bu 2\n")
}
@ -121,16 +124,16 @@ func (r *roffRenderer) Paragraph(out *bytes.Buffer, text func() bool) {
func (r *roffRenderer) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) {
out.WriteString("\n.TS\nallbox;\n")
max_delims := 0
maxDelims := 0
lines := strings.Split(strings.TrimRight(string(header), "\n")+"\n"+strings.TrimRight(string(body), "\n"), "\n")
for _, w := range lines {
cur_delims := strings.Count(w, "\t")
if cur_delims > max_delims {
max_delims = cur_delims
curDelims := strings.Count(w, "\t")
if curDelims > maxDelims {
maxDelims = curDelims
}
}
out.Write([]byte(strings.Repeat("l ", max_delims+1) + "\n"))
out.Write([]byte(strings.Repeat("l ", max_delims+1) + ".\n"))
out.Write([]byte(strings.Repeat("l ", maxDelims+1) + "\n"))
out.Write([]byte(strings.Repeat("l ", maxDelims+1) + ".\n"))
out.Write(header)
if len(header) > 0 {
out.Write([]byte("\n"))
@ -215,7 +218,7 @@ func (r *roffRenderer) Link(out *bytes.Buffer, link []byte, title []byte, conten
r.AutoLink(out, link, 0)
}
func (r *roffRenderer) RawHtmlTag(out *bytes.Buffer, tag []byte) {
func (r *roffRenderer) RawHtmlTag(out *bytes.Buffer, tag []byte) { // nolint: golint
out.Write(tag)
}
@ -236,25 +239,6 @@ func (r *roffRenderer) Entity(out *bytes.Buffer, entity []byte) {
out.WriteString(html.UnescapeString(string(entity)))
}
func processFooterText(text []byte) []byte {
text = bytes.TrimPrefix(text, []byte("% "))
newText := []byte{}
textArr := strings.Split(string(text), ") ")
for i, w := range textArr {
if i == 0 {
w = strings.Replace(w, "(", "\" \"", 1)
w = fmt.Sprintf("\"%s\"", w)
} else {
w = fmt.Sprintf(" \"%s\"", w)
}
newText = append(newText, []byte(w)...)
}
newText = append(newText, []byte(" \"\"")...)
return newText
}
func (r *roffRenderer) NormalText(out *bytes.Buffer, text []byte) {
escapeSpecialChars(out, text)
}

View File

@ -5,6 +5,20 @@ import (
"testing"
)
func TestTitleBlock(t *testing.T) {
r := &roffRenderer{}
buf := bytes.NewBuffer(nil)
title := []byte("% stuff\n% more stuff\n% even more stuff")
r.TitleBlock(buf, title)
expected := ".TH \"stuff\" \"more stuff\" \"even more stuff\" \n.nh\n.ad l\n"
actual := buf.String()
if expected != actual {
t.Fatalf("expected:\n%s\nactual:\n%s", expected, actual)
}
}
func TestBlockCode(t *testing.T) {
r := &roffRenderer{}
buf := bytes.NewBuffer(nil)
@ -37,7 +51,7 @@ func TestTableCell(t *testing.T) {
r.TableCell(buf, cell, 0)
expected := " "
if buf.String() != expected {
t.Fatal("expected %q, got %q", expected, buf.String())
t.Fatalf("expected %q, got %q", expected, buf.String())
}
r.TableCell(buf, cell, 0)

View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -eu -o pipefail
go get -u github.com/alecthomas/gometalinter
gometalinter --install >/dev/null
go get -u github.com/golang/dep/cmd/dep

18
vendor/github.com/cpuguy83/go-md2man/script/validate/vendor generated vendored Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eu -o pipefail
dep ensure
DIFF_PATH="vendor/"
DIFF=$(git status --porcelain -- "$DIFF_PATH")
if [ "$DIFF" ]; then
echo
echo "These files were modified:"
echo
echo "$DIFF"
echo
exit 1
else
echo "$DIFF_PATH is correct"
fi