gemtext

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: Unlicense Imports: 3 Imported by: 0

Documentation

Overview

The gemtext package contains a gemtext AST and parser.

Conversion sub-packages can convert this AST into other document types, and support overridable templates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document []Line

Document is the list of lines that make up a full text/gemini resource.

func Parse

func Parse(input io.Reader) (Document, error)

Parse parses the full contents of an io.Reader into a gemtext.Document.

type HeadingLine

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

HeadingLine is a line of LineTypeHeading[1,2,3].

func (HeadingLine) Body

func (hl HeadingLine) Body() string

Body returns the portion of the line with the header text.

func (HeadingLine) Raw

func (hl HeadingLine) Raw() []byte

func (HeadingLine) String

func (hl HeadingLine) String() string

func (HeadingLine) Type

func (hl HeadingLine) Type() LineType

type Line

type Line interface {
	// Type returns the specific type of the gemtext line.
	Type() LineType

	// Raw reproduces the original bytes from the source reader.
	Raw() []byte

	// String represents the original bytes from the source reader as a string.
	String() string
}

Line is the interface implemented by all specific line types.

Many of those concrete implementation types have additional useful fields, so it can be a good idea to cast these to their concrete types based on the return value of the Type() method.

func ParseLine

func ParseLine(line []byte) Line

ParseLine parses a single line (including the trailing \n) into a gemtext.Line.

type LineType

type LineType int

LineType represents the different types of lines in a gemtext document.

const (
	// LineTypeText is the default case when nothing else matches.
	//
	// It indicates that the line object is a TextLine.
	LineTypeText LineType = iota + 1

	// LineTypeLink is a link line.
	//
	// =>[<ws>]<url>[<ws><label>][\r]\n
	//
	// The line is a LinkLine.
	LineTypeLink

	// LineTypePrompt is a spartan =: prompt line.
	//
	// =:[<ws>]<url>[<ws><label>][\r]\n
	//
	// The line is a LinkLine.
	LineTypePrompt

	// LineTypePreformatToggle switches the document between pre-formatted text or not.
	//
	// “`[<alt-text>][\r]\n
	//
	// The line object is a PreformatToggleLine.
	LineTypePreformatToggle

	// LineTypePreformattedText is any line between two PreformatToggles.
	//
	// The line is a PreformattedTextLine.
	LineTypePreformattedText

	// LineTypeHeading1 is a top-level heading.
	//
	// #[<ws>]body[\r]\n
	//
	// The line is a HeadingLine.
	LineTypeHeading1

	// LineTypeHeading2 is a second-level heading.
	//
	// ##[<ws>]body[\r]\n
	//
	// The line is a HeadingLine.
	LineTypeHeading2

	// LineTypeHeading3 is a third-level heading.
	//
	// ###[<ws>]<body>[\r]\n
	//
	// The line is a HeadingLine.
	LineTypeHeading3

	// LineTypeListItem is an unordered list item.
	//
	// * <body>[\r]\n
	//
	// The line object is a ListItemLine.
	LineTypeListItem

	// LineTypeQuote is a quote line.
	//
	// ><body>[\r]\n
	//
	// The line object is a QuoteLine.
	LineTypeQuote
)

type LinkLine

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

LinkLine is a line of LineTypeLink.

func (LinkLine) Label

func (ll LinkLine) Label() string

Label returns the label portion of the line.

func (LinkLine) Raw

func (ll LinkLine) Raw() []byte

func (LinkLine) String

func (ll LinkLine) String() string

func (LinkLine) Type

func (ll LinkLine) Type() LineType

func (LinkLine) URL

func (ll LinkLine) URL() string

URL returns the original url portion of the line.

It is not guaranteed to be a valid URL.

type ListItemLine

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

ListItemLine is a line of LineTypeListItem.

func (ListItemLine) Body

func (li ListItemLine) Body() string

Body returns the text of the list item.

func (ListItemLine) Raw

func (li ListItemLine) Raw() []byte

func (ListItemLine) String

func (li ListItemLine) String() string

func (ListItemLine) Type

func (li ListItemLine) Type() LineType

type PreformatToggleLine

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

PreformatToggleLine is a preformatted text toggle line.

func (PreformatToggleLine) AltText

func (tl PreformatToggleLine) AltText() string

AltText returns the alt-text portion of the line.

If the line was parsed as part of a full document by Parse(), and this is a *closing* toggle, any alt-text present will be stripped and this will be empty. If the line was parsed by ParseLine() no such correction is performed.

func (PreformatToggleLine) Raw

func (tl PreformatToggleLine) Raw() []byte

func (PreformatToggleLine) String

func (tl PreformatToggleLine) String() string

func (PreformatToggleLine) Type

func (tl PreformatToggleLine) Type() LineType

type PreformattedTextLine

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

PreformattedTextLine represents a line between two toggles.

It is never returned by ParseLine but can be part of a document parsed by Parse().

func (PreformattedTextLine) Raw

func (tl PreformattedTextLine) Raw() []byte

func (PreformattedTextLine) String

func (tl PreformattedTextLine) String() string

func (PreformattedTextLine) Type

func (tl PreformattedTextLine) Type() LineType

type QuoteLine

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

QuoteLine is a line of LineTypeQuote.

func (QuoteLine) Body

func (ql QuoteLine) Body() string

Body returns the text of the quote.

func (QuoteLine) Raw

func (ql QuoteLine) Raw() []byte

func (QuoteLine) String

func (ql QuoteLine) String() string

func (QuoteLine) Type

func (ql QuoteLine) Type() LineType

type TextLine

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

TextLine is a line of LineTypeText.

func (TextLine) Raw

func (tl TextLine) Raw() []byte

func (TextLine) String

func (tl TextLine) String() string

func (TextLine) Type

func (tl TextLine) Type() LineType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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