2015-08-07 10:18:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Alex Yatskov <alex@foosoft.net>
|
|
|
|
* Author: Alex Yatskov <alex@foosoft.net>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2015-08-07 11:25:00 +00:00
|
|
|
"fmt"
|
2015-08-07 10:18:13 +00:00
|
|
|
"log"
|
2015-08-09 05:18:09 +00:00
|
|
|
"path"
|
2015-08-09 02:35:15 +00:00
|
|
|
"regexp"
|
2015-08-07 11:25:00 +00:00
|
|
|
"strings"
|
2015-08-07 10:18:13 +00:00
|
|
|
|
|
|
|
"github.com/russross/blackfriday"
|
|
|
|
)
|
|
|
|
|
2015-08-07 11:25:00 +00:00
|
|
|
const (
|
2015-08-11 05:56:14 +00:00
|
|
|
defNumCols = 80
|
|
|
|
defTabSize = 4
|
2015-08-07 11:25:00 +00:00
|
|
|
)
|
|
|
|
|
2015-08-09 05:37:09 +00:00
|
|
|
const (
|
2015-08-11 05:56:14 +00:00
|
|
|
flagNoToc = 1 << iota
|
|
|
|
flagNoRules
|
|
|
|
flagPascal
|
2015-08-09 05:37:09 +00:00
|
|
|
)
|
|
|
|
|
2015-08-09 02:35:15 +00:00
|
|
|
type list struct {
|
|
|
|
index int
|
2015-08-07 11:25:00 +00:00
|
|
|
}
|
|
|
|
|
2015-08-09 05:57:43 +00:00
|
|
|
type heading struct {
|
2015-08-19 07:39:28 +00:00
|
|
|
text []byte
|
|
|
|
level int
|
2015-08-09 04:12:17 +00:00
|
|
|
}
|
|
|
|
|
2015-08-07 10:18:13 +00:00
|
|
|
type vimDoc struct {
|
2015-08-09 05:18:09 +00:00
|
|
|
filename string
|
2015-08-09 04:12:17 +00:00
|
|
|
title string
|
2015-08-09 05:18:09 +00:00
|
|
|
desc string
|
2015-08-09 04:49:53 +00:00
|
|
|
cols int
|
|
|
|
tabs int
|
2015-08-09 05:37:09 +00:00
|
|
|
flags int
|
2015-08-09 04:12:17 +00:00
|
|
|
tocPos int
|
|
|
|
lists []*list
|
2015-08-19 07:39:28 +00:00
|
|
|
headings []*heading
|
2015-08-07 11:25:00 +00:00
|
|
|
}
|
|
|
|
|
2015-08-09 05:37:09 +00:00
|
|
|
func VimDocRenderer(filename, desc string, cols, tabs, flags int) blackfriday.Renderer {
|
2015-08-09 05:18:09 +00:00
|
|
|
filename = path.Base(filename)
|
|
|
|
title := filename
|
|
|
|
|
|
|
|
if index := strings.LastIndex(filename, "."); index > -1 {
|
2015-08-09 05:37:09 +00:00
|
|
|
title = filename[:index]
|
2015-08-11 05:56:14 +00:00
|
|
|
if flags&flagPascal == 0 {
|
2015-08-09 05:37:09 +00:00
|
|
|
title = strings.ToLower(title)
|
|
|
|
}
|
2015-08-09 05:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &vimDoc{
|
|
|
|
filename: filename,
|
|
|
|
title: title,
|
|
|
|
desc: desc,
|
|
|
|
cols: cols,
|
|
|
|
tabs: tabs,
|
2015-08-09 05:37:09 +00:00
|
|
|
flags: flags,
|
2015-08-09 05:18:09 +00:00
|
|
|
tocPos: -1}
|
2015-08-09 02:35:15 +00:00
|
|
|
}
|
|
|
|
|
2015-08-19 07:39:28 +00:00
|
|
|
func (v *vimDoc) fixupCodeTags(input []byte) []byte {
|
2015-08-09 02:35:15 +00:00
|
|
|
r := regexp.MustCompile(`(?m)^\s*([<>])$`)
|
|
|
|
return r.ReplaceAll(input, []byte("$1"))
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-19 07:39:28 +00:00
|
|
|
func (v *vimDoc) buildHelpTag(text []byte) []byte {
|
2015-08-11 05:56:14 +00:00
|
|
|
if v.flags&flagPascal == 0 {
|
2015-08-09 05:57:43 +00:00
|
|
|
text = bytes.ToLower(text)
|
|
|
|
text = bytes.Replace(text, []byte{' '}, []byte{'_'}, -1)
|
2015-08-09 05:37:09 +00:00
|
|
|
} else {
|
2015-08-09 05:57:43 +00:00
|
|
|
text = bytes.Title(text)
|
|
|
|
text = bytes.Replace(text, []byte{' '}, []byte{}, -1)
|
2015-08-09 05:37:09 +00:00
|
|
|
}
|
|
|
|
|
2015-08-09 05:57:43 +00:00
|
|
|
return []byte(fmt.Sprintf("%s-%s", v.title, text))
|
2015-08-09 04:12:17 +00:00
|
|
|
}
|
|
|
|
|
2015-08-19 07:39:28 +00:00
|
|
|
func (v *vimDoc) buildHeadingPrefix(h *heading) []byte {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *vimDoc) writeSplitText(out *bytes.Buffer, left, right []byte, repeat string, trim int) {
|
2015-08-09 04:49:53 +00:00
|
|
|
padding := v.cols - (len(left) + len(right)) + trim
|
2015-08-09 05:18:09 +00:00
|
|
|
if padding <= 0 {
|
|
|
|
padding = 1
|
|
|
|
}
|
2015-08-09 04:49:53 +00:00
|
|
|
|
|
|
|
out.Write(left)
|
2015-08-15 08:15:59 +00:00
|
|
|
out.WriteString(strings.Repeat(repeat, padding))
|
2015-08-09 04:49:53 +00:00
|
|
|
out.Write(right)
|
|
|
|
out.WriteString("\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *vimDoc) writeRule(out *bytes.Buffer, repeat string) {
|
|
|
|
out.WriteString(strings.Repeat(repeat, v.cols))
|
2015-08-08 03:09:12 +00:00
|
|
|
out.WriteString("\n")
|
|
|
|
}
|
|
|
|
|
2015-08-19 07:39:28 +00:00
|
|
|
func (v *vimDoc) writeToc(out *bytes.Buffer) {
|
|
|
|
for _, h := range v.headings {
|
|
|
|
title := fmt.Sprintf("%s%s", strings.Repeat(" ", (h.level-1)*v.tabs), h.text)
|
|
|
|
link := fmt.Sprintf("|%s|", v.buildHelpTag(h.text))
|
|
|
|
v.writeSplitText(out, []byte(title), []byte(link), ".", 2)
|
2015-08-09 04:12:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-19 07:39:28 +00:00
|
|
|
func (v *vimDoc) writeIndent(out *bytes.Buffer, text string, trim int) {
|
2015-08-08 10:58:23 +00:00
|
|
|
lines := strings.Split(text, "\n")
|
|
|
|
|
|
|
|
for index, line := range lines {
|
2015-08-09 04:49:53 +00:00
|
|
|
width := v.tabs
|
2015-08-09 04:12:17 +00:00
|
|
|
if width >= trim && index == 0 {
|
2015-08-08 10:58:23 +00:00
|
|
|
width -= trim
|
|
|
|
}
|
|
|
|
|
2015-08-09 04:49:53 +00:00
|
|
|
if len(line) > 0 {
|
|
|
|
out.WriteString(strings.Repeat(" ", width))
|
|
|
|
out.WriteString(line)
|
|
|
|
out.WriteString("\n")
|
2015-08-08 10:58:23 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-08 03:09:12 +00:00
|
|
|
}
|
|
|
|
|
2015-08-07 10:18:13 +00:00
|
|
|
// Block-level callbacks
|
2015-08-08 03:09:12 +00:00
|
|
|
func (v *vimDoc) BlockCode(out *bytes.Buffer, text []byte, lang string) {
|
2015-08-07 11:25:00 +00:00
|
|
|
out.WriteString(">\n")
|
2015-08-19 07:39:28 +00:00
|
|
|
v.writeIndent(out, string(text), 0)
|
2015-08-08 03:09:12 +00:00
|
|
|
out.WriteString("<\n\n")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-08 03:09:12 +00:00
|
|
|
func (v *vimDoc) BlockQuote(out *bytes.Buffer, text []byte) {
|
2015-08-07 11:25:00 +00:00
|
|
|
out.WriteString(">\n")
|
2015-08-19 07:39:28 +00:00
|
|
|
v.writeIndent(out, string(text), 0)
|
2015-08-08 03:09:12 +00:00
|
|
|
out.WriteString("<\n\n")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-08 03:09:12 +00:00
|
|
|
func (v *vimDoc) BlockHtml(out *bytes.Buffer, text []byte) {
|
2015-08-07 11:25:00 +00:00
|
|
|
out.WriteString(">\n")
|
2015-08-19 07:39:28 +00:00
|
|
|
v.writeIndent(out, string(text), 0)
|
2015-08-08 03:09:12 +00:00
|
|
|
out.WriteString("<\n\n")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-08 03:09:12 +00:00
|
|
|
func (v *vimDoc) Header(out *bytes.Buffer, text func() bool, level int, id string) {
|
2015-08-09 04:12:17 +00:00
|
|
|
initPos := out.Len()
|
2015-08-11 05:56:14 +00:00
|
|
|
if v.flags&flagNoRules == 0 {
|
2015-08-09 05:37:09 +00:00
|
|
|
switch level {
|
|
|
|
case 1:
|
|
|
|
v.writeRule(out, "=")
|
|
|
|
case 2:
|
|
|
|
v.writeRule(out, "-")
|
|
|
|
}
|
2015-08-08 03:09:12 +00:00
|
|
|
}
|
|
|
|
|
2015-08-09 05:57:43 +00:00
|
|
|
headingPos := out.Len()
|
2015-08-08 03:09:12 +00:00
|
|
|
if !text() {
|
2015-08-09 04:12:17 +00:00
|
|
|
out.Truncate(initPos)
|
2015-08-08 03:09:12 +00:00
|
|
|
return
|
2015-08-07 11:25:00 +00:00
|
|
|
}
|
2015-08-08 03:09:12 +00:00
|
|
|
|
2015-08-19 07:39:28 +00:00
|
|
|
if v.tocPos == -1 && len(v.headings) > 0 {
|
2015-08-09 04:12:17 +00:00
|
|
|
v.tocPos = initPos
|
|
|
|
}
|
|
|
|
|
2015-08-19 07:39:28 +00:00
|
|
|
var temp []byte
|
|
|
|
temp = append(temp, out.Bytes()[headingPos:]...)
|
2015-08-09 04:12:17 +00:00
|
|
|
|
2015-08-19 07:39:28 +00:00
|
|
|
h := &heading{temp, level}
|
|
|
|
v.headings = append(v.headings, h)
|
2015-08-09 04:12:17 +00:00
|
|
|
|
2015-08-09 05:57:43 +00:00
|
|
|
out.Truncate(headingPos)
|
2015-08-19 07:39:28 +00:00
|
|
|
tag := fmt.Sprintf("*%s*", v.buildHelpTag(h.text))
|
|
|
|
v.writeSplitText(out, bytes.ToUpper(h.text), []byte(tag), " ", 2)
|
2015-08-09 04:49:53 +00:00
|
|
|
out.WriteString("\n")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-08 03:09:12 +00:00
|
|
|
func (v *vimDoc) HRule(out *bytes.Buffer) {
|
2015-08-09 04:12:17 +00:00
|
|
|
v.writeRule(out, "-")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-07 11:25:00 +00:00
|
|
|
func (v *vimDoc) List(out *bytes.Buffer, text func() bool, flags int) {
|
2015-08-19 06:10:17 +00:00
|
|
|
v.lists = append(v.lists, &list{1})
|
2015-08-07 11:25:00 +00:00
|
|
|
text()
|
2015-08-19 06:10:17 +00:00
|
|
|
v.lists = v.lists[:len(v.lists)-1]
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-07 11:25:00 +00:00
|
|
|
func (v *vimDoc) ListItem(out *bytes.Buffer, text []byte, flags int) {
|
2015-08-08 10:58:23 +00:00
|
|
|
marker := out.Len()
|
2015-08-08 03:09:12 +00:00
|
|
|
|
2015-08-19 06:10:17 +00:00
|
|
|
list := v.lists[len(v.lists)-1]
|
2015-08-09 02:35:15 +00:00
|
|
|
if flags&blackfriday.LIST_TYPE_ORDERED == blackfriday.LIST_TYPE_ORDERED {
|
2015-08-08 03:09:12 +00:00
|
|
|
out.WriteString(fmt.Sprintf("%d. ", list.index))
|
|
|
|
list.index++
|
|
|
|
} else {
|
|
|
|
out.WriteString("* ")
|
|
|
|
}
|
|
|
|
|
2015-08-19 07:39:28 +00:00
|
|
|
v.writeIndent(out, string(text), out.Len()-marker)
|
2015-08-08 03:09:12 +00:00
|
|
|
|
2015-08-09 04:49:53 +00:00
|
|
|
if flags&blackfriday.LIST_ITEM_END_OF_LIST != 0 {
|
2015-08-08 03:09:12 +00:00
|
|
|
out.WriteString("\n")
|
|
|
|
}
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) Paragraph(out *bytes.Buffer, text func() bool) {
|
2015-08-07 11:25:00 +00:00
|
|
|
marker := out.Len()
|
2015-08-09 04:49:53 +00:00
|
|
|
|
2015-08-07 11:25:00 +00:00
|
|
|
if !text() {
|
|
|
|
out.Truncate(marker)
|
|
|
|
return
|
|
|
|
}
|
2015-08-09 04:49:53 +00:00
|
|
|
|
2015-08-08 03:09:12 +00:00
|
|
|
out.WriteString("\n\n")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-09 05:57:43 +00:00
|
|
|
func (*vimDoc) Table(out *bytes.Buffer, heading []byte, body []byte, columnData []int) {
|
2015-08-08 03:09:12 +00:00
|
|
|
// unimplemented
|
2015-08-19 06:12:42 +00:00
|
|
|
log.Println("Table is a stub")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) TableRow(out *bytes.Buffer, text []byte) {
|
2015-08-08 03:09:12 +00:00
|
|
|
// unimplemented
|
2015-08-19 06:12:42 +00:00
|
|
|
log.Println("TableRow is a stub")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) TableHeaderCell(out *bytes.Buffer, text []byte, flags int) {
|
2015-08-08 03:09:12 +00:00
|
|
|
// unimplemented
|
2015-08-19 06:12:42 +00:00
|
|
|
log.Println("TableHeaderCell is a stub")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) TableCell(out *bytes.Buffer, text []byte, flags int) {
|
2015-08-08 03:09:12 +00:00
|
|
|
// unimplemented
|
2015-08-19 06:12:42 +00:00
|
|
|
log.Println("TableCell is a stub")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) Footnotes(out *bytes.Buffer, text func() bool) {
|
2015-08-08 03:09:12 +00:00
|
|
|
// unimplemented
|
2015-08-19 06:12:42 +00:00
|
|
|
log.Println("Footnotes is a stub")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int) {
|
2015-08-08 03:09:12 +00:00
|
|
|
// unimplemented
|
2015-08-19 06:12:42 +00:00
|
|
|
log.Println("FootnoteItem is a stub")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) TitleBlock(out *bytes.Buffer, text []byte) {
|
2015-08-08 03:09:12 +00:00
|
|
|
// unimplemented
|
2015-08-19 06:12:42 +00:00
|
|
|
log.Println("TitleBlock is a stub")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Span-level callbacks
|
|
|
|
func (*vimDoc) AutoLink(out *bytes.Buffer, link []byte, kind int) {
|
2015-08-07 11:25:00 +00:00
|
|
|
out.Write(link)
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) CodeSpan(out *bytes.Buffer, text []byte) {
|
2015-08-09 02:35:15 +00:00
|
|
|
r := regexp.MustCompile(`\s`)
|
|
|
|
|
2015-08-09 04:49:53 +00:00
|
|
|
// vim does not correctly highlight space-delimited words in code spans
|
2015-08-09 02:35:15 +00:00
|
|
|
if !r.Match(text) {
|
|
|
|
out.WriteString("`")
|
|
|
|
out.Write(text)
|
|
|
|
out.WriteString("`")
|
|
|
|
}
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) DoubleEmphasis(out *bytes.Buffer, text []byte) {
|
2015-08-07 11:25:00 +00:00
|
|
|
out.Write(text)
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) Emphasis(out *bytes.Buffer, text []byte) {
|
2015-08-07 11:25:00 +00:00
|
|
|
out.Write(text)
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) {
|
2015-08-09 04:12:17 +00:00
|
|
|
// cannot view images in vim
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) LineBreak(out *bytes.Buffer) {
|
2015-08-07 11:25:00 +00:00
|
|
|
out.WriteString("\n")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) {
|
2015-08-07 11:25:00 +00:00
|
|
|
out.WriteString(fmt.Sprintf("%s (%s)", content, link))
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) RawHtmlTag(out *bytes.Buffer, tag []byte) {
|
2015-08-09 02:35:15 +00:00
|
|
|
// unimplemented
|
2015-08-19 06:12:42 +00:00
|
|
|
log.Println("StrikeThrough is a stub")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) TripleEmphasis(out *bytes.Buffer, text []byte) {
|
2015-08-07 11:25:00 +00:00
|
|
|
out.Write(text)
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) StrikeThrough(out *bytes.Buffer, text []byte) {
|
2015-08-08 03:09:12 +00:00
|
|
|
// unimplemented
|
2015-08-19 06:12:42 +00:00
|
|
|
log.Println("StrikeThrough is a stub")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*vimDoc) FootnoteRef(out *bytes.Buffer, ref []byte, id int) {
|
2015-08-08 03:09:12 +00:00
|
|
|
// unimplemented
|
2015-08-19 06:12:42 +00:00
|
|
|
log.Println("FootnoteRef is a stub")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Low-level callbacks
|
2015-08-08 03:09:12 +00:00
|
|
|
func (v *vimDoc) Entity(out *bytes.Buffer, entity []byte) {
|
2015-08-07 11:25:00 +00:00
|
|
|
out.Write(entity)
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-08 03:09:12 +00:00
|
|
|
func (v *vimDoc) NormalText(out *bytes.Buffer, text []byte) {
|
2015-08-07 11:25:00 +00:00
|
|
|
out.Write(text)
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Header and footer
|
2015-08-09 05:18:09 +00:00
|
|
|
func (v *vimDoc) DocumentHeader(out *bytes.Buffer) {
|
|
|
|
if len(v.desc) > 0 {
|
2015-08-19 07:39:28 +00:00
|
|
|
v.writeSplitText(out, []byte(v.filename), []byte(v.desc), " ", 0)
|
2015-08-09 05:18:09 +00:00
|
|
|
} else {
|
|
|
|
out.WriteString(v.filename)
|
|
|
|
out.WriteString("\n")
|
|
|
|
}
|
2015-08-09 05:42:25 +00:00
|
|
|
|
|
|
|
out.WriteString("\n")
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-09 04:12:17 +00:00
|
|
|
func (v *vimDoc) DocumentFooter(out *bytes.Buffer) {
|
|
|
|
var temp bytes.Buffer
|
|
|
|
|
2015-08-11 05:56:14 +00:00
|
|
|
if v.tocPos > 0 && v.flags&flagNoToc == 0 {
|
2015-08-09 04:58:39 +00:00
|
|
|
temp.Write(out.Bytes()[:v.tocPos])
|
2015-08-19 07:39:28 +00:00
|
|
|
v.writeToc(&temp)
|
2015-08-09 04:58:39 +00:00
|
|
|
temp.WriteString("\n")
|
|
|
|
temp.Write(out.Bytes()[v.tocPos:])
|
|
|
|
} else {
|
|
|
|
temp.ReadFrom(out)
|
|
|
|
}
|
2015-08-09 04:12:17 +00:00
|
|
|
|
|
|
|
out.Reset()
|
2015-08-19 07:39:28 +00:00
|
|
|
out.Write(v.fixupCodeTags(temp.Bytes()))
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-09 05:37:09 +00:00
|
|
|
func (v *vimDoc) GetFlags() int {
|
|
|
|
return v.flags
|
2015-08-07 10:18:13 +00:00
|
|
|
}
|