Documentation ¶
Overview ¶
Package seed reads and writes Seed documents.
Index ¶
- Constants
- Variables
- func Copy(sw *Writer, sr *Reader) (err error)
- type Code
- type Header
- type Line
- type Link
- type Quote
- type Reader
- type Text
- type Writer
- func (sw *Writer) Code() (err error)
- func (sw *Writer) Header(level int, txt string) (err error)
- func (sw *Writer) InBlock() bool
- func (sw *Writer) Line(line Line) (err error)
- func (sw *Writer) Link(txt, url string) (err error)
- func (sw *Writer) Quote() (err error)
- func (sw *Writer) Text(txt string) (err error)
Constants ¶
const (
// Extension is the standard filename extension for Seed documents.
Extension = ".sd"
)
Variables ¶
var ( // ErrBadLine indicates that it is illegal to insert the line. This usually // happens when putting a non-text line in a quote or code block. ErrBadLine = errors.New("line type cannot be added here") // ErrInvalidHeaderLvl indicates that the header level is invalid. A header // level must be between 1 and 6. ErrInvalidHeaderLvl = errors.New("invalid header level given") // ErrInvalidLine indicates that the given line type couldn't be converted // to a valid line type. ErrInvalidLine = errors.New("invalid line type given") )
Functions ¶
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads a Seed document.
sr := seed.NewReader(...) for { line, err := sr.ReadLine() if err == io.EOF { break } else if err != nil { return err } switch l := line.(type) { case seed.Header: fmt.Printf("header: level=%d text=%q\n", l.Level, l.Text) case seed.Text: fmt.Printf("text: text=%s\n", string(l)) default: fmt.Println("other line type") } }
As can be seen above, the Reader reads a single line at a time. Type switches or type assertions can be to gather info on the line.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer writes documents in the Seed format.
Doc:
# Lorem ipsum >>> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. >>> => Lorem ipsum ||| https://en.wikipedia.org/wiki/Lorem_ipsum
Code:
sw := seed.NewWriter(...) sw.Header(1, "Lorem ipsum") sw.Break() sw.Quote() sw.Text("Lorem ipsum dolor sit amet,") sw.Text("consectetur adipiscing elit,") sw.Text("sed do eiusmod tempor incididunt") sw.Text("ut labore et dolore magna aliqua.") sw.Quote() sw.Break() sw.Link("Lorem ipsum", "https://en.wikipedia.org/wiki/Lorem_ipsum")
As can be seen above, the Writer writes a single line every time one of it's line methods is called.
func (*Writer) Code ¶
Code writes a code marker line to w. All following text lines are part of the code block. The code marker indicates the start and end of a code block. It is invalid to put anything other than text lines in a code block and all other line methods will return ErrBadLine in this case.
func (*Writer) Line ¶
Line adds a line to w. The type of this line is determined by the given line. If line is a not a valid line type, err is ErrBadLine.
func (*Writer) Quote ¶
Quote writes a quote marker line to w. All following text lines are part of the quote. The quote marker indicates the start and end of a quote block. It is invalid to put anything other than text lines in a quote block and all other line methods will return ErrBadLine in this case.