Style changes
This commit is contained in:
parent
408830ec4e
commit
d4137012b8
16
md2vim.go
16
md2vim.go
@ -41,8 +41,8 @@ func usage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cols := flag.Int("cols", DEFAULT_NUM_COLUMNS, "number of columns to use for layout")
|
cols := flag.Int("cols", defNumCols, "number of columns to use for layout")
|
||||||
tabs := flag.Int("tabs", DEFAULT_TAB_SIZE, "tab width specified in number of spaces")
|
tabs := flag.Int("tabs", defTabSize, "tab width specified in number of spaces")
|
||||||
notoc := flag.Bool("notoc", false, "do not generate table of contents for headings")
|
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")
|
norules := flag.Bool("norules", false, "do not generate horizontal rules above headings")
|
||||||
pascal := flag.Bool("pascal", false, "use PascalCase for abbreviating tags")
|
pascal := flag.Bool("pascal", false, "use PascalCase for abbreviating tags")
|
||||||
@ -58,18 +58,18 @@ func main() {
|
|||||||
|
|
||||||
input, err := ioutil.ReadFile(args[0])
|
input, err := ioutil.ReadFile(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error: unable to read from file %s", args[0])
|
log.Fatalf("unable to read from file: %s", args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := 0
|
flags := 0
|
||||||
if *notoc {
|
if *notoc {
|
||||||
flags |= FLAG_NO_TOC
|
flags |= flagNoToc
|
||||||
}
|
}
|
||||||
if *norules {
|
if *norules {
|
||||||
flags |= FLAG_NO_RULES
|
flags |= flagNoRules
|
||||||
}
|
}
|
||||||
if *pascal {
|
if *pascal {
|
||||||
flags |= FLAG_PASCAL
|
flags |= flagPascal
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer := VimDocRenderer(args[1], *desc, *cols, *tabs, flags)
|
renderer := VimDocRenderer(args[1], *desc, *cols, *tabs, flags)
|
||||||
@ -78,11 +78,11 @@ func main() {
|
|||||||
|
|
||||||
file, err := os.Create(args[1])
|
file, err := os.Create(args[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error: unable to write to file %s", args[1])
|
log.Fatalf("unable to write to file: %s", args[1])
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
if _, err := file.Write(output); err != nil {
|
if _, err := file.Write(output); err != nil {
|
||||||
log.Fatal("error: unable to write output")
|
log.Fatal("unable to write output")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
vimdoc.go
26
vimdoc.go
@ -34,14 +34,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DEFAULT_NUM_COLUMNS = 80
|
defNumCols = 80
|
||||||
DEFAULT_TAB_SIZE = 4
|
defTabSize = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FLAG_NO_TOC = 1 << iota
|
flagNoToc = 1 << iota
|
||||||
FLAG_NO_RULES
|
flagNoRules
|
||||||
FLAG_PASCAL
|
flagPascal
|
||||||
)
|
)
|
||||||
|
|
||||||
type list struct {
|
type list struct {
|
||||||
@ -73,7 +73,7 @@ func VimDocRenderer(filename, desc string, cols, tabs, flags int) blackfriday.Re
|
|||||||
|
|
||||||
if index := strings.LastIndex(filename, "."); index > -1 {
|
if index := strings.LastIndex(filename, "."); index > -1 {
|
||||||
title = filename[:index]
|
title = filename[:index]
|
||||||
if flags&FLAG_PASCAL == 0 {
|
if flags&flagPascal == 0 {
|
||||||
title = strings.ToLower(title)
|
title = strings.ToLower(title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,18 +93,10 @@ func (v *vimDoc) pushl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *vimDoc) popl() {
|
func (v *vimDoc) popl() {
|
||||||
if len(v.lists) == 0 {
|
|
||||||
log.Fatal("error: invalid list operation")
|
|
||||||
}
|
|
||||||
|
|
||||||
v.lists = v.lists[:len(v.lists)-1]
|
v.lists = v.lists[:len(v.lists)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *vimDoc) getl() *list {
|
func (v *vimDoc) getl() *list {
|
||||||
if len(v.lists) == 0 {
|
|
||||||
log.Fatal("error: invalid list operation")
|
|
||||||
}
|
|
||||||
|
|
||||||
return v.lists[len(v.lists)-1]
|
return v.lists[len(v.lists)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +110,7 @@ func (v *vimDoc) fixupHeader(text []byte) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *vimDoc) buildTag(text []byte) []byte {
|
func (v *vimDoc) buildTag(text []byte) []byte {
|
||||||
if v.flags&FLAG_PASCAL == 0 {
|
if v.flags&flagPascal == 0 {
|
||||||
text = bytes.ToLower(text)
|
text = bytes.ToLower(text)
|
||||||
text = bytes.Replace(text, []byte{' '}, []byte{'_'}, -1)
|
text = bytes.Replace(text, []byte{' '}, []byte{'_'}, -1)
|
||||||
} else {
|
} else {
|
||||||
@ -195,7 +187,7 @@ 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 {
|
if v.flags&flagNoRules == 0 {
|
||||||
switch level {
|
switch level {
|
||||||
case 1:
|
case 1:
|
||||||
v.writeRule(out, "=")
|
v.writeRule(out, "=")
|
||||||
@ -397,7 +389,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 && v.flags&FLAG_NO_TOC == 0 {
|
if v.tocPos > 0 && v.flags&flagNoToc == 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")
|
||||||
|
Loading…
Reference in New Issue
Block a user