pax_global_header00006660000000000000000000000064126426145030014515gustar00rootroot0000000000000052 comment=2724a9c9051aa62e9cca11304e7dd518e9e41599 go-md2man-1.0.5/000077500000000000000000000000001264261450300133015ustar00rootroot00000000000000go-md2man-1.0.5/.gitignore000066400000000000000000000000121264261450300152620ustar00rootroot00000000000000go-md2man go-md2man-1.0.5/LICENSE.md000066400000000000000000000020651264261450300147100ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 Brian Goff Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. go-md2man-1.0.5/README.md000066400000000000000000000003551264261450300145630ustar00rootroot00000000000000go-md2man ========= ** Work in Progress ** This still needs a lot of help to be complete, or even usable! Uses blackfriday to process markdown into man pages. ### Usage ./md2man -in /path/to/markdownfile.md -out /manfile/output/path go-md2man-1.0.5/go-md2man.1.md000066400000000000000000000011321264261450300155400ustar00rootroot00000000000000go-md2man 1 "January 2015" go-md2man "User Manual" ================================================== # NAME go-md2man - Convert mardown files into manpages # SYNOPSIS go-md2man -in=[/path/to/md/file] -out=[/path/to/output] # Description go-md2man converts standard markdown formatted documents into manpages. It is written purely in Go so as to reduce dependencies on 3rd party libs. # Example Convert the markdown file "go-md2man.1.md" into a manpage. go-md2man -in=README.md -out=go-md2man.1.out # HISTORY January 2015, Originally compiled by Brian Goff( cpuguy83@gmail.com ) go-md2man-1.0.5/md2man.go000066400000000000000000000013001264261450300150000ustar00rootroot00000000000000package main import ( "flag" "fmt" "io/ioutil" "os" "github.com/cpuguy83/go-md2man/md2man" ) var inFilePath = flag.String("in", "", "Path to file to be processed") var outFilePath = flag.String("out", "", "Path to output processed file") func main() { flag.Parse() inFile, err := os.Open(*inFilePath) if err != nil { fmt.Println(err) os.Exit(1) } defer inFile.Close() doc, err := ioutil.ReadAll(inFile) if err != nil { fmt.Println(err) os.Exit(1) } out := md2man.Render(doc) outFile, err := os.Create(*outFilePath) if err != nil { fmt.Println(err) os.Exit(1) } defer outFile.Close() _, err = outFile.Write(out) if err != nil { fmt.Println(err) os.Exit(1) } } go-md2man-1.0.5/md2man/000077500000000000000000000000001264261450300144575ustar00rootroot00000000000000go-md2man-1.0.5/md2man/md2man.go000066400000000000000000000010351264261450300161630ustar00rootroot00000000000000package md2man import ( "github.com/russross/blackfriday" ) func Render(doc []byte) []byte { renderer := RoffRenderer(0) extensions := 0 extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS extensions |= blackfriday.EXTENSION_TABLES extensions |= blackfriday.EXTENSION_FENCED_CODE extensions |= blackfriday.EXTENSION_AUTOLINK extensions |= blackfriday.EXTENSION_SPACE_HEADERS extensions |= blackfriday.EXTENSION_FOOTNOTES extensions |= blackfriday.EXTENSION_TITLEBLOCK return blackfriday.Markdown(doc, renderer, extensions) } go-md2man-1.0.5/md2man/roff.go000066400000000000000000000137751264261450300157570ustar00rootroot00000000000000package md2man import ( "bytes" "fmt" "html" "strings" "github.com/russross/blackfriday" ) type roffRenderer struct{} var listCounter int func RoffRenderer(flags int) blackfriday.Renderer { return &roffRenderer{} } func (r *roffRenderer) GetFlags() int { return 0 } func (r *roffRenderer) TitleBlock(out *bytes.Buffer, text []byte) { out.WriteString(".TH ") splitText := bytes.Split(text, []byte("\n")) for i, line := range splitText { line = bytes.TrimPrefix(line, []byte("% ")) if i == 0 { line = bytes.Replace(line, []byte("("), []byte("\" \""), 1) line = bytes.Replace(line, []byte(")"), []byte("\" \""), 1) } line = append([]byte("\""), line...) line = append(line, []byte("\" ")...) out.Write(line) } out.WriteString("\n") // disable hyphenation out.WriteString(".nh\n") // disable justification (adjust text to left margin only) out.WriteString(".ad l\n") } func (r *roffRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string) { out.WriteString("\n.PP\n.RS\n\n.nf\n") escapeSpecialChars(out, text) out.WriteString("\n.fi\n.RE\n") } func (r *roffRenderer) BlockQuote(out *bytes.Buffer, text []byte) { out.WriteString("\n.PP\n.RS\n") out.Write(text) out.WriteString("\n.RE\n") } func (r *roffRenderer) BlockHtml(out *bytes.Buffer, text []byte) { out.Write(text) } func (r *roffRenderer) Header(out *bytes.Buffer, text func() bool, level int, id string) { marker := out.Len() switch { case marker == 0: // This is the doc header out.WriteString(".TH ") case level == 1: out.WriteString("\n\n.SH ") case level == 2: out.WriteString("\n.SH ") default: out.WriteString("\n.SS ") } if !text() { out.Truncate(marker) return } } func (r *roffRenderer) HRule(out *bytes.Buffer) { out.WriteString("\n.ti 0\n\\l'\\n(.lu'\n") } func (r *roffRenderer) List(out *bytes.Buffer, text func() bool, flags int) { marker := out.Len() if flags&blackfriday.LIST_TYPE_ORDERED != 0 { listCounter = 1 } if !text() { out.Truncate(marker) return } } 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 } else { out.WriteString(".IP \\(bu 2\n") } out.Write(text) out.WriteString("\n") } func (r *roffRenderer) Paragraph(out *bytes.Buffer, text func() bool) { marker := out.Len() out.WriteString("\n.PP\n") if !text() { out.Truncate(marker) return } if marker != 0 { out.WriteString("\n") } } // TODO: This might now work func (r *roffRenderer) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) { out.WriteString(".TS\nallbox;\n") out.Write(header) out.Write(body) out.WriteString("\n.TE\n") } func (r *roffRenderer) TableRow(out *bytes.Buffer, text []byte) { if out.Len() > 0 { out.WriteString("\n") } out.Write(text) out.WriteString("\n") } func (r *roffRenderer) TableHeaderCell(out *bytes.Buffer, text []byte, align int) { if out.Len() > 0 { out.WriteString(" ") } out.Write(text) out.WriteString(" ") } // TODO: This is probably broken func (r *roffRenderer) TableCell(out *bytes.Buffer, text []byte, align int) { if out.Len() > 0 { out.WriteString("\t") } out.Write(text) out.WriteString("\t") } func (r *roffRenderer) Footnotes(out *bytes.Buffer, text func() bool) { } func (r *roffRenderer) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int) { } func (r *roffRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) { out.WriteString("\n\\[la]") out.Write(link) out.WriteString("\\[ra]") } func (r *roffRenderer) CodeSpan(out *bytes.Buffer, text []byte) { out.WriteString("\\fB\\fC") escapeSpecialChars(out, text) out.WriteString("\\fR") } func (r *roffRenderer) DoubleEmphasis(out *bytes.Buffer, text []byte) { out.WriteString("\\fB") out.Write(text) out.WriteString("\\fP") } func (r *roffRenderer) Emphasis(out *bytes.Buffer, text []byte) { out.WriteString("\\fI") out.Write(text) out.WriteString("\\fP") } func (r *roffRenderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) { } func (r *roffRenderer) LineBreak(out *bytes.Buffer) { out.WriteString("\n.br\n") } func (r *roffRenderer) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) { r.AutoLink(out, link, 0) } func (r *roffRenderer) RawHtmlTag(out *bytes.Buffer, tag []byte) { out.Write(tag) } func (r *roffRenderer) TripleEmphasis(out *bytes.Buffer, text []byte) { out.WriteString("\\s+2") out.Write(text) out.WriteString("\\s-2") } func (r *roffRenderer) StrikeThrough(out *bytes.Buffer, text []byte) { } func (r *roffRenderer) FootnoteRef(out *bytes.Buffer, ref []byte, id int) { } 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) } func (r *roffRenderer) DocumentHeader(out *bytes.Buffer) { } func (r *roffRenderer) DocumentFooter(out *bytes.Buffer) { } func needsBackslash(c byte) bool { for _, r := range []byte("-_&\\~") { if c == r { return true } } return false } func escapeSpecialChars(out *bytes.Buffer, text []byte) { for i := 0; i < len(text); i++ { // escape initial apostrophe or period if len(text) >= 1 && (text[0] == '\'' || text[0] == '.') { out.WriteString("\\&") } // directly copy normal characters org := i for i < len(text) && !needsBackslash(text[i]) { i++ } if i > org { out.Write(text[org:i]) } // escape a character if i >= len(text) { break } out.WriteByte('\\') out.WriteByte(text[i]) } }