Adding flags
This commit is contained in:
parent
b19b5a829b
commit
a2eed618e3
43
vimdoc.go
43
vimdoc.go
@ -38,6 +38,12 @@ const (
|
||||
DEFAULT_TAB_SIZE = 4
|
||||
)
|
||||
|
||||
const (
|
||||
FLAG_NO_TOC = 1 << iota
|
||||
FLAG_NO_RULES
|
||||
FLAG_PASCAL
|
||||
)
|
||||
|
||||
type list struct {
|
||||
index int
|
||||
}
|
||||
@ -54,18 +60,22 @@ type vimDoc struct {
|
||||
desc string
|
||||
cols int
|
||||
tabs int
|
||||
flags int
|
||||
tocPos int
|
||||
lists []*list
|
||||
rootHead *header
|
||||
lastHead *header
|
||||
}
|
||||
|
||||
func VimDocRenderer(filename, desc string, cols, tabs int) blackfriday.Renderer {
|
||||
func VimDocRenderer(filename, desc string, cols, tabs, flags int) blackfriday.Renderer {
|
||||
filename = path.Base(filename)
|
||||
title := filename
|
||||
|
||||
if index := strings.LastIndex(filename, "."); index > -1 {
|
||||
title = strings.ToLower(filename[:index])
|
||||
title = filename[:index]
|
||||
if flags&FLAG_PASCAL == 0 {
|
||||
title = strings.ToLower(title)
|
||||
}
|
||||
}
|
||||
|
||||
return &vimDoc{
|
||||
@ -74,6 +84,7 @@ func VimDocRenderer(filename, desc string, cols, tabs int) blackfriday.Renderer
|
||||
desc: desc,
|
||||
cols: cols,
|
||||
tabs: tabs,
|
||||
flags: flags,
|
||||
tocPos: -1}
|
||||
}
|
||||
|
||||
@ -107,8 +118,14 @@ func (v *vimDoc) fixupHeader(header []byte) []byte {
|
||||
}
|
||||
|
||||
func (v *vimDoc) buildTag(header []byte) []byte {
|
||||
header = bytes.ToLower(header)
|
||||
header = bytes.Replace(header, []byte{' '}, []byte{'_'}, -1)
|
||||
if v.flags&FLAG_PASCAL == 0 {
|
||||
header = bytes.ToLower(header)
|
||||
header = bytes.Replace(header, []byte{' '}, []byte{'_'}, -1)
|
||||
} else {
|
||||
header = bytes.ToTitle(header)
|
||||
header = bytes.Replace(header, []byte{' '}, []byte{}, -1)
|
||||
}
|
||||
|
||||
return []byte(fmt.Sprintf("%s-%s", v.title, header))
|
||||
}
|
||||
|
||||
@ -178,11 +195,13 @@ func (v *vimDoc) BlockHtml(out *bytes.Buffer, text []byte) {
|
||||
func (v *vimDoc) Header(out *bytes.Buffer, text func() bool, level int, id string) {
|
||||
initPos := out.Len()
|
||||
|
||||
switch level {
|
||||
case 1:
|
||||
v.writeRule(out, "=")
|
||||
case 2:
|
||||
v.writeRule(out, "-")
|
||||
if v.flags&FLAG_NO_RULES == 0 {
|
||||
switch level {
|
||||
case 1:
|
||||
v.writeRule(out, "=")
|
||||
case 2:
|
||||
v.writeRule(out, "-")
|
||||
}
|
||||
}
|
||||
|
||||
headerPos := out.Len()
|
||||
@ -376,7 +395,7 @@ func (v *vimDoc) DocumentHeader(out *bytes.Buffer) {
|
||||
func (v *vimDoc) DocumentFooter(out *bytes.Buffer) {
|
||||
var temp bytes.Buffer
|
||||
|
||||
if v.tocPos > 0 {
|
||||
if v.tocPos > 0 && v.flags&FLAG_NO_TOC == 0 {
|
||||
temp.Write(out.Bytes()[:v.tocPos])
|
||||
v.writeToc(&temp, v.rootHead, 0)
|
||||
temp.WriteString("\n")
|
||||
@ -389,6 +408,6 @@ func (v *vimDoc) DocumentFooter(out *bytes.Buffer) {
|
||||
out.Write(v.fixupCode(temp.Bytes()))
|
||||
}
|
||||
|
||||
func (*vimDoc) GetFlags() int {
|
||||
return 0
|
||||
func (v *vimDoc) GetFlags() int {
|
||||
return v.flags
|
||||
}
|
||||
|
20
vimdown.go
20
vimdown.go
@ -40,8 +40,11 @@ func usage() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
cols := flag.Int("cols", 80, "number of columns to use for alignment and rules")
|
||||
tabs := flag.Int("tabs", 4, "size of the tab to use specified as number of spaces")
|
||||
cols := flag.Int("cols", DEFAULT_NUM_COLUMNS, "number of columns to use for alignment and rules")
|
||||
tabs := flag.Int("tabs", DEFAULT_TAB_SIZE, "size of the tab to use specified as number of spaces")
|
||||
notoc := flag.Bool("notoc", false, "do not generate table of contents for headings")
|
||||
norules := flag.Bool("norules", false, "do not generate horizontal rules above headings")
|
||||
pascal := flag.Bool("pascal", false, "use PascalCase for abbreviating tags")
|
||||
desc := flag.String("desc", "", "short description of extension")
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
@ -57,7 +60,18 @@ func main() {
|
||||
log.Fatalf("error: unable to read from file %s", args[0])
|
||||
}
|
||||
|
||||
renderer := VimDocRenderer(args[1], *desc, *cols, *tabs)
|
||||
flags := 0
|
||||
if *notoc {
|
||||
flags |= FLAG_NO_TOC
|
||||
}
|
||||
if *norules {
|
||||
flags |= FLAG_NO_RULES
|
||||
}
|
||||
if *pascal {
|
||||
flags |= FLAG_PASCAL
|
||||
}
|
||||
|
||||
renderer := VimDocRenderer(args[1], *desc, *cols, *tabs, flags)
|
||||
extensions := blackfriday.EXTENSION_FENCED_CODE | blackfriday.EXTENSION_NO_INTRA_EMPHASIS | blackfriday.EXTENSION_SPACE_HEADERS
|
||||
output := blackfriday.Markdown(input, renderer, extensions)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user