gemtext

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package gemtext provides utilities for building and parsing Gemtext documents

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

A Builder is an object capable of building a Gemtext document

func NewBuilder

func NewBuilder() Builder

NewBuilder creates a new Builder

func (*Builder) AddHeader1Line

func (b *Builder) AddHeader1Line(text string) *Builder

AddHeader1Line adds a top level header line

func (*Builder) AddHeader2Line

func (b *Builder) AddHeader2Line(text string) *Builder

AddHeader2Line adds a secondary level header line

func (*Builder) AddHeader3Line

func (b *Builder) AddHeader3Line(text string) *Builder

AddHeader3Line adds a tertiary level header line

func (*Builder) AddLinkLine

func (b *Builder) AddLinkLine(url string, name ...string) *Builder

AddLinkLine adds a new link line.

While more than two args can be passed to it, any additional arguments will be ignored for the time being

func (*Builder) AddPreformattedText

func (b *Builder) AddPreformattedText(text string) *Builder

AddPreformattedText adds a block of preformatted text

func (*Builder) AddQuoteLine

func (b *Builder) AddQuoteLine(text string) *Builder

AddQuoteLine adds a blockquoted line

func (*Builder) AddTextLine

func (b *Builder) AddTextLine(line string) *Builder

AddTextLine adds a new text line (i.e. no additional formatting) to the Builder

func (*Builder) AddUnorderedList

func (b *Builder) AddUnorderedList(items []string) *Builder

AddUnorderedList adds an unordered list

func (*Builder) Get

func (b *Builder) Get() string

Get gets the Gemtext content of the Builder

type Header1Line added in v0.1.0

type Header1Line struct {
	// Text is the text of the header
	Text string
}

Header1Line is a primary header

func (Header1Line) Type added in v0.1.0

func (h Header1Line) Type() LineType

type Header2Line added in v0.1.0

type Header2Line struct {
	// Text is the text of the header
	Text string
}

Header2Line is a secondary header

func (Header2Line) Type added in v0.1.0

func (h Header2Line) Type() LineType

type Header3Line added in v0.1.0

type Header3Line struct {
	// Text is the text of the header
	Text string
}

Header3Line is a tertiary header

func (Header3Line) Type added in v0.1.0

func (h Header3Line) Type() LineType

type Line added in v0.1.0

type Line interface {
	// Type returns the type of the line
	Type() LineType
}

Line is any object representing a Gemtext line

func Parse added in v0.1.0

func Parse(source string) ([]Line, error)

Parse parses a Gemtext document into a slice of Lines

type LineType added in v0.1.0

type LineType int

LineType is an enumeration representing a Gemtext line type

const (
	// Text marks a plain text line, with no additional formatting
	Text LineType = iota
	// Link marks a hyperlink line
	Link
	// Preformatted marks a block of preformatted text
	Preformatted
	// Header1 marks a primary header
	Header1
	// Header2 marks a secondary header
	Header2
	// Header3 marks a tertiary header
	Header3
	// ListItem marks an item in an unordered list
	ListItem
	// Quote marks a blockquoted line
	Quote
)

type LinkLine added in v0.1.0

type LinkLine struct {
	// Destination is the line's destination
	Destination string // TODO: Maybe make this a url.URL?
	// Text is the line's (optional) body text
	Text string
}

LinkLine is a hyperlink line

func (LinkLine) Type added in v0.1.0

func (l LinkLine) Type() LineType

type ListItemLine added in v0.1.0

type ListItemLine struct {
	// Text is the text of the list item
	Text string
}

ListItemLine is a item in an unordered list

func (ListItemLine) Type added in v0.1.0

func (l ListItemLine) Type() LineType

type PreformattedText added in v0.1.0

type PreformattedText struct {
	// AltText is the block's alt text; often used for language syntax highlighting
	AltText string
	// Body is the body of the block
	Body string
}

PreformattedText is a block of preformatted text

func (PreformattedText) Type added in v0.1.0

func (p PreformattedText) Type() LineType

type QuoteLine added in v0.1.0

type QuoteLine struct {
	// Text is the text within the quote
	Text string
}

QuoteLine is a blockquoted line

func (QuoteLine) Type added in v0.1.0

func (q QuoteLine) Type() LineType

type TextLine added in v0.1.0

type TextLine struct {
	// Text is the line's text
	Text string
}

TextLine is a plain text line, with no additional formatting

func (TextLine) Type added in v0.1.0

func (t TextLine) Type() LineType

Jump to

Keyboard shortcuts

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