mdbook

package
v1.5.28 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package mdbook is a helper for writing mdbook plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Args

func Args(argv []string)

Args implements handling the expected CLI arguments.

This function calls os.Exit under the right circumstances.

func Decode

func Decode(r io.Reader) (*Context, *Book, error)

Decode reads the Context and Book JSON objects from the passed io.Reader. This should be almost always be os.Stdin.

func Main

func Main(name string, pf ProcFunc)

Main is a simple replacement main for mdbook preprocessors.

Types

type Book

type Book struct {
	Sections []Section `json:"sections"`
	X        *struct{} `json:"__non_exhaustive"`
}

Book is an mdbook book.

type BookConfig

type BookConfig struct {
	Authors      []string `json:"authors"`
	Source       string   `json:"src"`
	Description  string   `json:"description"`
	Language     string   `json:"language"`
	Title        string   `json:"title"`
	MultiLingual bool     `json:"multilingual"`
}

BookConfig is the mdbook metadata and configuration.

type BookItem

type BookItem interface {
	Chapter | Separator | PartTitle
}

BookItem is one of Chapter, Separator, or PartTitle.

type Chapter

type Chapter struct {
	Name        string    `json:"name"`
	Content     string    `json:"content"`
	Number      []int     `json:"number"`
	SubItems    []Section `json:"sub_items"`
	Path        *string   `json:"path"`
	SourcePath  *string   `json:"source_path"`
	ParentNames []string  `json:"parent_names"`
}

Chapter is an mdbook chapter.

type Context

type Context struct {
	Root     string `json:"root"`
	Renderer string `json:"renderer"`
	Version  string `json:"mdbook_version"`
	Config   struct {
		Book   BookConfig                 `json:"book"`
		Output map[string]json.RawMessage `json:"output"`
	} `json:"config"`
	Preprocessor map[string]json.RawMessage `json:"preprocessor"`
}

Context is the whole mdbook context.

type Hook

type Hook[I BookItem] func(ctx context.Context, b *strings.Builder, item *I) error

Hook is a hook function to modify a BookItem in-place.

type PartTitle

type PartTitle string

PartTitle is the title of the current part.

type Proc

type Proc struct {
	Chapter   Hook[Chapter]
	Separator Hook[Separator]
	PartTitle Hook[PartTitle]
}

Proc is a helper for modifying a Book.

func (*Proc) Walk

func (p *Proc) Walk(ctx context.Context, book *Book) error

Walk walks the provided Book, calling the [Hook]s in the member fields as needed to modify elements in-place.

type ProcFunc

type ProcFunc func(context.Context, *Context) (*Proc, error)

ProcFunc is a hook for creating a new Proc.

type Section

type Section struct {
	Chapter   *Chapter   `json:",omitempty"`
	Separator *Separator `json:",omitempty"`
	PartTitle *PartTitle `json:",omitempty"`
}

Section is one of a Chapter, Separator, or PartTitle.

type Separator

type Separator struct{}

Separator denotes an mdbook separator.

Jump to

Keyboard shortcuts

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