toast

package
v0.0.0-...-c8d73de Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: MIT, Unlicense Imports: 5 Imported by: 0

README

# CosmicToast Gemini Parser

This is a clone of toast.cafe/x/gmi, a Gemini text parser by CosmicToast.  This is used to compare the performance and characteristics of my own parser.

The following was run to rename the package and remove unused packages and tests from the library.

```sh
rm -rf go.mod cmd dprint *_test.go
sed -i '' 's|package gmi|package toast|' *.go
```

This was cloned on 2020 December 13 and the latest clone on master:

```git
commit 4547f1f3a67617c7916e9bf0a3d1b98c4b2c0447 (HEAD -> master)
Author: Chloe Kudryavtsev <toast@toast.cafe>
Date:   Thu Aug 6 16:15:44 2020 -0400

    fix silly typo (missing range keyword)
```

Relevant links:

=> https://github.com/CosmicToast/gmi GitHub Source
=> https://toast.cafe/x/gmi toast.cafe/x/gmi
=> https://godoc.org/toast.cafe/x/gmi GoDocs Documentation
=> https://pkg.go.dev/toast.cafe/x/gmi pkg.go.dev Documentation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heading

type Heading struct {
	HL [maxHeading]int // current section number, extendable in case we get >3 headings
	// for example, {1, 3, 0} is # followed by 3 ##s
	H *HeadingLine
}

Heading represents a Heading in a TOC context, alongside its associated 3 levels within the overall structure

func (Heading) Numbered

func (r Heading) Numbered() string

Numbered returns a pretty-printed string representing the numbering component of the heading in the document

func (Heading) String

func (r Heading) String() string

type HeadingLine

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

HeadingLine represents a heading text/gemini line

func (HeadingLine) CoreType

func (r HeadingLine) CoreType() LineType

func (HeadingLine) Data

func (r HeadingLine) Data() string

func (HeadingLine) Level

func (r HeadingLine) Level() int

func (HeadingLine) Meta

func (r HeadingLine) Meta() string

func (HeadingLine) Prefix

func (r HeadingLine) Prefix() string

func (HeadingLine) String

func (r HeadingLine) String() string

func (HeadingLine) Type

func (r HeadingLine) Type() LineType

type Line

type Line interface {
	CoreType() LineType // CoreType returns the core type of the line (returns Text Type for advanced line types)
	Type() LineType     // Type returns the true type of the line
	Level() int         // Level returns the level of the heading, if it's a HeadingType, or 0 otherwise

	Data() string   // Data returns the content data of the line
	Meta() string   // Meta returns the secondary data of the line (e.g the link for link lines), if any
	Prefix() string // Prefix returns the documented prefix to the line, without whitespace

	String() string // String (Stringer) implements a post-formatted representation of the original line, including prefix
}

Line represents a Line in text/gemini in a logical way

type LineType

type LineType int

LineType represents a text/gemini line type

const (
	TextType LineType = iota
	LinkType
	PreformatToggleType
	PreformatType
	HeadingType
	UnorderedListType
	QuoteType
)

Line Types

type LinkLine

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

LinkLine represents a link text/gemini line

func (LinkLine) CoreType

func (r LinkLine) CoreType() LineType

func (LinkLine) Data

func (r LinkLine) Data() string

func (LinkLine) Level

func (r LinkLine) Level() int

func (LinkLine) Meta

func (r LinkLine) Meta() string

func (LinkLine) Prefix

func (r LinkLine) Prefix() string

func (LinkLine) String

func (r LinkLine) String() string

func (LinkLine) Type

func (r LinkLine) Type() LineType

type Parser

type Parser struct {
	Lines []Line
	// contains filtered or unexported fields
}

Parser handles parsing of a text/gemini document

func NewParser

func NewParser(r io.Reader) *Parser

NewParser instantiates a new parser from a reader

func (*Parser) Parse

func (p *Parser) Parse() error

Parse will parse the provided input until termination The returned error will be non-nil only if a significant error occured

func (*Parser) TOC

func (p *Parser) TOC(force bool) []*Heading

TOC returns the calculated Table of Contents The returned structure is the list of just the headings of the parsed output. Force forces the recalculation of the TOC if it was already calculated, in case you changed the underlying structure.

func (*Parser) Title

func (p *Parser) Title() string

Title will calculate the title from the TOC (without forcing recalculation) and return one is one is found Title is considered to be whatever the first '#' heading is

type PreformatLine

type PreformatLine string

PreformatLine represents a preformatted text/gemini line

func (PreformatLine) CoreType

func (r PreformatLine) CoreType() LineType

func (PreformatLine) Data

func (r PreformatLine) Data() string

func (PreformatLine) Level

func (r PreformatLine) Level() int

func (PreformatLine) Meta

func (r PreformatLine) Meta() string

func (PreformatLine) Prefix

func (r PreformatLine) Prefix() string

func (PreformatLine) String

func (r PreformatLine) String() string

func (PreformatLine) Type

func (r PreformatLine) Type() LineType

type PreformatToggleLine

type PreformatToggleLine string

PreformatToggleLine represents a "```" toggle in text/gemini

func (PreformatToggleLine) CoreType

func (r PreformatToggleLine) CoreType() LineType

func (PreformatToggleLine) Data

func (r PreformatToggleLine) Data() string

func (PreformatToggleLine) Level

func (r PreformatToggleLine) Level() int

func (PreformatToggleLine) Meta

func (r PreformatToggleLine) Meta() string

func (PreformatToggleLine) Prefix

func (r PreformatToggleLine) Prefix() string

func (PreformatToggleLine) String

func (r PreformatToggleLine) String() string

func (PreformatToggleLine) Type

func (r PreformatToggleLine) Type() LineType

type QuoteLine

type QuoteLine string

QuoteLine represents a quoted text/gemini line

func (QuoteLine) CoreType

func (r QuoteLine) CoreType() LineType

func (QuoteLine) Data

func (r QuoteLine) Data() string

func (QuoteLine) Level

func (r QuoteLine) Level() int

func (QuoteLine) Meta

func (r QuoteLine) Meta() string

func (QuoteLine) Prefix

func (r QuoteLine) Prefix() string

func (QuoteLine) String

func (r QuoteLine) String() string

func (QuoteLine) Type

func (r QuoteLine) Type() LineType

type TextLine

type TextLine string

TextLine represents a text text/gemini line

func (TextLine) CoreType

func (r TextLine) CoreType() LineType

func (TextLine) Data

func (r TextLine) Data() string

func (TextLine) Level

func (r TextLine) Level() int

func (TextLine) Meta

func (r TextLine) Meta() string

func (TextLine) Prefix

func (r TextLine) Prefix() string

func (TextLine) String

func (r TextLine) String() string

func (TextLine) Type

func (r TextLine) Type() LineType

type UnorderedListLine

type UnorderedListLine string

UnorderedListLine represents an unordered list entry in text/gemini

func (UnorderedListLine) CoreType

func (r UnorderedListLine) CoreType() LineType

func (UnorderedListLine) Data

func (r UnorderedListLine) Data() string

func (UnorderedListLine) Level

func (r UnorderedListLine) Level() int

func (UnorderedListLine) Meta

func (r UnorderedListLine) Meta() string

func (UnorderedListLine) Prefix

func (r UnorderedListLine) Prefix() string

func (UnorderedListLine) String

func (r UnorderedListLine) String() string

func (UnorderedListLine) Type

func (r UnorderedListLine) Type() LineType

Jump to

Keyboard shortcuts

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