plugin

package
v0.0.0-...-66bc30b Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EachCommand

func EachCommand(book *Book, cmd string, callback func(chapter *BookChapter, args string) (string, error)) error

EachCommand looks for mustache-like declarations of the form `{{#cmd args}}` in each book chapter, and calls the callback for each one, substituting it for the result.

func EachItem

func EachItem(parentItem *BookItem, visitor ChapterVisitor) error

EachItem calls the given visitor for each chapter in the given item, passing a pointer to the actual chapter that the visitor can modify.

func EachItemInBook

func EachItemInBook(book *Book, visitor ChapterVisitor) error

EachItemInBook functions identically to EachItem, except that it visits all chapters in the book.

func Run

func Run(plug Plugin, inputRaw io.Reader, outputRaw io.Writer, args ...string) error

Run runs the given plugin on the given input stream, outputting its result to the given result, assuming the given command-line args (without program name).

Types

type Book

type Book struct {
	Sections      []BookItem `json:"sections"`
	NonExhaustive *struct{}  `json:"__non_exhaustive"`
}

Book is an mdBook book.

type BookChapter

type BookChapter struct {
	Name        string        `json:"name"`
	Content     string        `json:"content"`
	Number      SectionNumber `json:"number"`
	SubItems    []BookItem    `json:"sub_items"`
	Path        string        `json:"path"`
	ParentNames []string      `json:"parent_names"`
}

BookChapter is an mdBook chapter.

type BookConfig

type BookConfig struct {
	Src string `json:"src"`
}

BookConfig is a (partial) mdBook [book] stanza

type BookItem

type BookItem bookItem

BookItem is an mdBook item. It wraps an underlying struct to provide proper marshalling and unmarshalling according to what serde produces/expects.

func (BookItem) MarshalJSON

func (b BookItem) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json.Marshaler

func (*BookItem) UnmarshalJSON

func (b *BookItem) UnmarshalJSON(input []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler

type BookSection

type BookSection struct {
	Items []BookItem `json:"items"`
}

BookSection is an mdBook section.

type ChapterVisitor

type ChapterVisitor func(*BookChapter) error

ChapterVisitor visits each BookChapter in a book, getting an actual pointer to the chapter that it can modify.

type Config

type Config struct {
	Book BookConfig `json:"book"`
}

Config is a (partial) mdBook config

type Context

type Context struct {
	Root   string `json:"root"`
	Config Config `json:"config"`
}

Context is a (partial) mdBook execution context.

type Input

type Input struct {
	Context Context
	Book    Book
}

Input is the tuple that's presented to mdBook plugins. It's deserialized from a slice `[context, book]`, matching a Rust tuple.

func (*Input) UnmarshalJSON

func (p *Input) UnmarshalJSON(input []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler

type Plugin

type Plugin interface {
	// SupportsOutput checks if the given plugin supports the given output format.
	SupportsOutput(string) bool
	// Process modifies the book in the input, which gets returned as the result of the plugin.
	Process(*Input) error
}

Plugin represents a mdBook plugin.

type SectionNumber

type SectionNumber []uint32

SectionNumber is an mdBook section number (e.g. `1.2` is `{1,2}`).

Jump to

Keyboard shortcuts

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