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