stitch

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2024 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package stitch defines the core data types for a stitch document.

Summary is the full summary file, comprised of one or more [Section]s, each of which in turn has one or more [Item]s.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmbedItem added in v0.8.0

type EmbedItem struct {
	// Title of the link.
	// This is the text inside the "[..]" section.
	Text string

	// Target is the destination of this item.
	// This is the text inside the "(..)" section of the link.
	// It's /-separated, even on Windows.
	Target string

	// Depth is the depth of this item in the table of contents.
	Depth int

	// AST holds the original node.
	AST ast.Node
}

EmbedItem is a reference to another summary file intended to be nested in the table of contents.

![Foo](foo.md)

func (*EmbedItem) ItemDepth added in v0.8.0

func (i *EmbedItem) ItemDepth() int

ItemDepth reports the depth of this embed request in the TOC.

func (*EmbedItem) Node added in v0.8.0

func (i *EmbedItem) Node() ast.Node

Node returns the original AST node in the summary file that this item is built from.

type Item

type Item interface {
	ItemDepth() int
	Node() ast.Node
	// contains filtered or unexported methods
}

Item is a single item in a section. It can be a LinkItem or a TextItem.

type LinkItem

type LinkItem struct {
	// Text of the item.
	// This is the text inside the "[..]" section of the link.
	Text string

	// Target is the destination of this item.
	// This is the text inside the "(..)" section of the link.
	// It's /-separated, even on Windows.
	Target string

	// Depth is the depth of the item in the table of contents.
	// Depth starts at zero for top-level items.
	Depth int

	// AST holds the original link node.
	AST *ast.Link
}

LinkItem is a single link item in a table of contents.

[Foo](foo.md)

func (*LinkItem) ItemDepth added in v0.2.0

func (i *LinkItem) ItemDepth() int

ItemDepth reports the depth of the item in the table of contents.

func (*LinkItem) Node

func (i *LinkItem) Node() ast.Node

Node reports the underlying AST node that this item was parsed from.

type Section

type Section struct {
	Title *SectionTitle

	// Items lists the items in the section
	// and their nested items.
	Items tree.List[Item]

	// AST holds the original list
	// from which this Section was built.
	AST *ast.List
}

Section is a single section of a summary document. It's comprised of an optional title and a tree of items.

type SectionTitle

type SectionTitle struct {
	// Text of the title.
	Text string

	// Level of the title.
	Level int

	// AST node that this title was built from.
	AST *ast.Heading
}

SectionTitle holds information about a section title.

type Summary

type Summary struct {
	// Sections is a list of sections in the summary.
	Sections []*Section
}

Summary is the complete summary document. It's comprised of one or more sections.

func ParseSummary

func ParseSummary(f *goldast.File) (*Summary, error)

ParseSummary parses a summary from a Markdown document. The summary is expected in a very specific format:

  • it's comprised of one or more sections
  • each section has an optional title header and a list of items
  • each item is either a link to a Markdown document or a plain text title
  • items may be nested to indicate a hierarchy

For example:

# User Guide

- [Getting Started](getting-started.md)
    - [Installation](installation.md)
- Options
    - [foo](foo.md)
    - [bar](bar.md)
- [Reference](reference.md)

# Appendix

- [FAQ](faq.md)

Anything else will result in an error.

type TextItem

type TextItem struct {
	// Text of the item.
	Text string

	// Depth is the depth of the item in the table of contents.
	// Depth starts at zero for top-level items.
	Depth int

	// AST holds the original text node.
	AST *ast.Text
}

TextItem is a single text entry in the table of contents.

Foo

func (*TextItem) ItemDepth added in v0.2.0

func (i *TextItem) ItemDepth() int

ItemDepth reports the depth of the item in the table of contents.

func (*TextItem) Node

func (i *TextItem) Node() ast.Node

Node reports the underlying AST node that this item was parsed from.

Jump to

Keyboard shortcuts

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