mdbook

package
v1.5.54 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 6 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 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.

Types

type Book

type Book struct {
	Items []Item    `json:"items"`
	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    []Item   `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 Item added in v1.5.46

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

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

type PartTitle

type PartTitle string

PartTitle is the title of the current part.

type Proc

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

Proc is a helper for modifying a Book.

func NewProc added in v1.5.53

func NewProc(ctx context.Context, cfg *Context, fs ...RegisterFunc) (*Proc, error)

NewProc returns a Proc with the provided [RegisterFunc]s called on it.

func (*Proc) Chapter

func (p *Proc) Chapter(h Hook[Chapter])

Chapter registers a Chapter Hook.

func (*Proc) PartTitle

func (p *Proc) PartTitle(h Hook[PartTitle])

PartTitle registers a PartTitle Hook.

func (*Proc) Separator

func (p *Proc) Separator(h Hook[Separator])

Separator registers a Separator Hook.

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 RegisterFunc added in v1.5.53

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

RegisterFunc is the type for arranging to have a preprocessor's hooks called.

Implmentations should use the passed context.Context and Context, then call functions to register hooks in the Proc as needed.

type Separator

type Separator struct{}

Separator denotes an mdbook separator.

Directories

Path Synopsis
Package godoc is an mdbook preprocessor to inline `go doc` output.
Package godoc is an mdbook preprocessor to inline `go doc` output.
Package injecturls is an mdbook preprocessor meant to collect urls via a comment directive.
Package injecturls is an mdbook preprocessor meant to collect urls via a comment directive.
Package maketarget is an mdbook preprocessor to check that documented Makefile targets exist.
Package maketarget is an mdbook preprocessor to check that documented Makefile targets exist.
Package mermaid is an mdbook preprocessor meant to slip-stream mermaid diagrams.
Package mermaid is an mdbook preprocessor meant to slip-stream mermaid diagrams.

Jump to

Keyboard shortcuts

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