Document struct

Document wraps types.Document adding helper methods.

Methods:

writef


Parameters:
  • format string
  • args ...any

Show/Hide Method Body
{
	if bytes.HasSuffix(d.Buffer.Bytes(), []byte("\n")) && strings.HasPrefix(format, "\n") {
		format = strings.TrimPrefix(format, "\n")
	}
	fmt.Fprintf(&d.Buffer, format, args...)
}

writelnf


Parameters:
  • format string
  • args ...any

Show/Hide Method Body
{
	d.writef(format+"\n", args...)
}

Heading

Heading writes the document heading.


Parameters:
  • section uint
  • title string
  • desc string
  • ts time.Time

Show/Hide Method Body
{
	d.writef(types.TitleHeading, strings.ToUpper(title), section, title, ts.Format("2006-01-02"), desc)
}

Paragraph

Paragraph starts a new paragraph.


Show/Hide Method Body
{ d.writelnf(types.Paragraph) }

Indent

Indent increases the indentation level.


Parameters:
  • n int

Show/Hide Method Body
{
	if n >= 0 {
		d.writelnf(types.Indent+" %d", n)
	} else {
		d.writelnf(types.Indent)
	}
}

IndentEnd

IndentEnd decreases the indentation level.


Show/Hide Method Body
{ d.writelnf(types.IndentEnd) }

TaggedParagraph

TaggedParagraph starts a tagged paragraph.


Parameters:
  • indentation int

Show/Hide Method Body
{
	if indentation >= 0 {
		d.writelnf(types.TaggedParagraph+" %d", indentation)
	} else {
		d.writelnf(types.TaggedParagraph)
	}
}

List

List writes a list item.


Parameters:
  • text string

Show/Hide Method Body
{
	d.writelnf(types.IndentedParagraph+" \\(bu 3\n%s", escapeText(strings.TrimSpace(text)))
}

Section

Section writes a section heading.


Parameters:
  • text string

Show/Hide Method Body
{
	d.writelnf(types.SectionHeading, strings.ToUpper(text))
}

SubSection

SubSection writes a subsection heading.


Parameters:
  • text string

Show/Hide Method Body
{
	d.writelnf(types.SubSectionHeading, strings.ToUpper(text))
}

EndSection

EndSection ends the current section.


Show/Hide Method Body
{ d.writelnf("") }

EndSubSection

EndSubSection ends the current subsection.


Show/Hide Method Body
{ d.writelnf("") }

Text

Text writes text handling basic lists.


Parameters:
  • text string

Show/Hide Method Body
{
	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

TextBold writes bold text.


Parameters:
  • text string

Show/Hide Method Body
{
	d.writef(types.Bold)
	d.Text(text)
	d.writef(types.PreviousFont)
}

TextItalic

TextItalic writes italic text.


Parameters:
  • text string

Show/Hide Method Body
{
	d.writef(types.Italic)
	d.Text(text)
	d.writef(types.PreviousFont)
}

String

String returns the document as a string.


Returns:
  • string

Show/Hide Method Body
{ return d.Buffer.String() }

NewDocument function

NewDocument creates a new roff document.

Returns:

  • *Document
Show/Hide Function Body
{
	return &Document{}
}

escapeText function

Parameters:

  • s string

Returns:

  • string
Show/Hide Function Body
{
	s = strings.ReplaceAll(s, `\`, `\e`)
	s = strings.ReplaceAll(s, ".", "\\&.")
	return s
}

bytes import

Import example:

import "bytes"

fmt import

Import example:

import "fmt"

strings import

Import example:

import "strings"

time import

Import example:

import "time"

github.com/vanilla-os/sdk/pkg/v1/roff/types import

Import example:

import "github.com/vanilla-os/sdk/pkg/v1/roff/types"