Document wraps types.Document adding helper methods.
{
if bytes.HasSuffix(d.Buffer.Bytes(), []byte("\n")) && strings.HasPrefix(format, "\n") {
format = strings.TrimPrefix(format, "\n")
}
fmt.Fprintf(&d.Buffer, format, args...)
}
{
d.writef(format+"\n", args...)
}
Heading writes the document heading.
{
d.writef(types.TitleHeading, strings.ToUpper(title), section, title, ts.Format("2006-01-02"), desc)
}
Paragraph starts a new paragraph.
{ d.writelnf(types.Paragraph) }
Indent increases the indentation level.
{
if n >= 0 {
d.writelnf(types.Indent+" %d", n)
} else {
d.writelnf(types.Indent)
}
}
IndentEnd decreases the indentation level.
{ d.writelnf(types.IndentEnd) }
TaggedParagraph starts a tagged paragraph.
{
if indentation >= 0 {
d.writelnf(types.TaggedParagraph+" %d", indentation)
} else {
d.writelnf(types.TaggedParagraph)
}
}
List writes a list item.
{
d.writelnf(types.IndentedParagraph+" \\(bu 3\n%s", escapeText(strings.TrimSpace(text)))
}
Section writes a section heading.
{
d.writelnf(types.SectionHeading, strings.ToUpper(text))
}
SubSection writes a subsection heading.
{
d.writelnf(types.SubSectionHeading, strings.ToUpper(text))
}
EndSection ends the current section.
{ d.writelnf("") }
EndSubSection ends the current subsection.
{ d.writelnf("") }
Text writes text handling basic lists.
{
inList := false
for i, line := range strings.Split(text, "\n") {
if i > 0 && !inList {
d.Paragraph()
}
if strings.HasPrefix(line, "*") {
if !inList {
d.Indent(-1)
inList = true
}
d.List(line[1:])
} else {
if inList {
d.IndentEnd()
inList = false
}
d.writef(escapeText(line))
}
}
}
TextBold writes bold text.
{
d.writef(types.Bold)
d.Text(text)
d.writef(types.PreviousFont)
}
TextItalic writes italic text.
{
d.writef(types.Italic)
d.Text(text)
d.writef(types.PreviousFont)
}
String returns the document as a string.
{ return d.Buffer.String() }
NewDocument creates a new roff document.
{
return &Document{}
}
{
s = strings.ReplaceAll(s, `\`, `\e`)
s = strings.ReplaceAll(s, ".", "\\&.")
return s
}
import "bytes"
import "fmt"
import "strings"
import "time"
import "github.com/vanilla-os/sdk/pkg/v1/roff/types"