roff

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2022 License: MIT Imports: 4 Imported by: 82

README

roff

Latest Release Build Status Coverage Status Go ReportCard GoDoc

roff lets you write roff documents in Go

Tutorial

Import the library:

import "github.com/muesli/roff"

Then start a new roff document and write to it:

doc := roff.NewDocument()
doc.Heading(1, "Title", "A short description", time.Now())

// a section of text
doc.Section("Introduction")
doc.Text("Here is a quick introduction to writing roff documents with Go!")

// fonts
doc.Section("Fonts")
doc.Text("This is a text with a bold font: ")
doc.TextBold("I am bold!")
doc.Paragraph()
doc.Text("This is a text with an italic font: ")
doc.TextItalic("I am italic!")

// indentation
doc.Section("Indentation")
doc.Text("This block of text is left-aligned to the section.")
doc.Indent(4)
doc.Text("This block of text is totally indented.")
doc.IndentEnd()
doc.Text("... left-aligned again!")

// lists
doc.Section("Lists")
doc.Text("A list:")
doc.Paragraph()
doc.Indent(4)
doc.List("First list item")
doc.List("Second list item")

Fetch the roff document as a string and you're done:

fmt.Println(doc.String())

Feedback

Got some feedback or suggestions? Please open an issue or drop me a note!

Documentation

Index

Constants

View Source
const (
	// Title heading (Document structure macro)
	TitleHeading = `.TH %[1]s %[2]d "%[4]s" "%[3]s" "%[5]s"`
	// Paragraph macro
	Paragraph = "\n.PP"
	// Relative-indent start (Document structure macro)
	Indent = "\n.RS"
	// Relative-indent end (Document structure macro)
	IndentEnd = "\n.RE"
	// Indented paragraph
	IndentedParagraph = "\n.IP"
	// Section heading (Document structure macro)
	SectionHeading = "\n.SH %s"
	// Tagged paragraph
	TaggedParagraph = "\n.TP"

	// Bold escape
	Bold = `\fB`
	// Italic escape
	Italic = `\fI`
	// Return to previous font setting
	PreviousFont = `\fP`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document is a roff document.

func NewDocument

func NewDocument() *Document

NewDocument returns a new roff Document.

func (*Document) EndSection

func (tr *Document) EndSection()

EndSection ends the current section.

func (*Document) Heading

func (tr *Document) Heading(section uint, title, description string, ts time.Time)

Heading writes the title heading of the document.

func (*Document) Indent

func (tr *Document) Indent(n int)

Indent increases the indentation level.

func (*Document) IndentEnd

func (tr *Document) IndentEnd()

IndentEnd decreases the indentation level.

func (*Document) List

func (tr *Document) List(text string)

List writes a list item.

func (*Document) Paragraph

func (tr *Document) Paragraph()

Paragraph starts a new paragraph.

func (*Document) Section

func (tr *Document) Section(text string)

Section writes a section heading.

func (Document) String

func (tr Document) String() string

String returns the roff document as a string.

func (*Document) TaggedParagraph

func (tr *Document) TaggedParagraph(indentation int)

TaggedParagraph starts a new tagged paragraph.

func (*Document) Text

func (tr *Document) Text(text string)

Text writes text.

func (*Document) TextBold

func (tr *Document) TextBold(text string)

TextBold writes text in bold.

func (*Document) TextItalic

func (tr *Document) TextItalic(text string)

TextItalic writes text in italic.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL