Documentation
¶
Index ¶
- Constants
- func AttrMatches(ats *Attributes, query map[string]string) bool
- func ByType[T Node](nodes Nodes) []T
- func DefaultElements() map[Atom]ParseElementFn
- func FindTitle(nodes Nodes) string
- func FirstByType[T Node](nodes Nodes) (T, bool)
- func GoVersion() string
- func IsEmptyNode(node Node) bool
- func Language(ats *Attributes, lang string) string
- func RestripeFigureIDs(nodes Nodes, fn IDGenerator) error
- func WrapNodeErr(n Node, err error) error
- type Atom
- type Atomable
- type AtomableNode
- type AttrNode
- type Attributes
- type Body
- type Cmd
- type CmdError
- type CmdResult
- type Comment
- type Document
- func (doc *Document) Body() (*Body, error)
- func (doc *Document) Children() Nodes
- func (doc *Document) Execute(ctx context.Context) (err error)
- func (doc *Document) Format(f fmt.State, verb rune)
- func (doc *Document) MD() string
- func (doc *Document) MarshalJSON() ([]byte, error)
- func (doc *Document) Pages() ([]*Page, error)
- func (doc *Document) String() string
- type Documents
- type Element
- func (el *Element) Atom() Atom
- func (el *Element) Attrs() *Attributes
- func (el *Element) Children() Nodes
- func (el *Element) EndTag() string
- func (el *Element) FileName() string
- func (el *Element) Format(f fmt.State, verb rune)
- func (el *Element) HTML() *html.Node
- func (el *Element) JSONMap() (map[string]any, error)
- func (el *Element) MD() string
- func (el *Element) MarshalJSON() ([]byte, error)
- func (el *Element) Set(k string, v string) error
- func (el *Element) StartTag() string
- func (el *Element) String() string
- func (el *Element) ValidAttr(k string) (string, error)
- func (el *Element) WrapErr(err error) error
- type EmptyableNode
- type ErrAttrEmpty
- type ErrAttrNotFound
- type ErrIsNil
- type ExecutableNode
- type ExecuteError
- type ExecuteFn
- type FencedCode
- type Figcaption
- type Figure
- type HTMLNode
- type Heading
- type IDGenerator
- type Image
- type Include
- type InlineCode
- type LI
- type Link
- type MDNode
- type Metadata
- type Node
- type Nodes
- func GenerateToC(p *Parser, nodes Nodes) (Nodes, error)
- func NewAttrCode(p *Parser, el *Element) (Nodes, error)
- func NewBodyNodes(p *Parser, el *Element) (Nodes, error)
- func NewCmdNodes(p *Parser, el *Element) (Nodes, error)
- func NewCodeNodes(p *Parser, el *Element) (Nodes, error)
- func NewFencedCodeNodes(p *Parser, el *Element) (Nodes, error)
- func NewFigcaptionNodes(p *Parser, el *Element) (Nodes, error)
- func NewFigureNodes(p *Parser, el *Element) (Nodes, error)
- func NewGoDocLinkNodes(p *Parser, el *Element) (Nodes, error)
- func NewGolangNodes(p *Parser, el *Element) (Nodes, error)
- func NewGolangs(p *Parser, el *Element) (Nodes, error)
- func NewHeadingNodes(p *Parser, el *Element) (Nodes, error)
- func NewImageNodes(p *Parser, el *Element) (Nodes, error)
- func NewIncludeNodes(p *Parser, el *Element) (Nodes, error)
- func NewInlineCodeNodes(p *Parser, el *Element) (Nodes, error)
- func NewLINodes(p *Parser, el *Element) (Nodes, error)
- func NewLinkNodes(p *Parser, el *Element) (Nodes, error)
- func NewMetadataNodes(p *Parser, el *Element) (Nodes, error)
- func NewNowNodes(p *Parser, el *Element) (Nodes, error)
- func NewOLNodes(p *Parser, el *Element) (Nodes, error)
- func NewPageNodes(p *Parser, el *Element) (Nodes, error)
- func NewParagraphNodes(p *Parser, el *Element) (Nodes, error)
- func NewRefNodes(p *Parser, el *Element) (Nodes, error)
- func NewSourceCodeNodes(p *Parser, el *Element) (Nodes, error)
- func NewTDNodes(p *Parser, el *Element) (Nodes, error)
- func NewTHNodes(p *Parser, el *Element) (Nodes, error)
- func NewTHeadNodes(p *Parser, el *Element) (Nodes, error)
- func NewTRNodes(p *Parser, el *Element) (Nodes, error)
- func NewTableNodes(p *Parser, el *Element) (Nodes, error)
- func NewToCNodes(p *Parser, el *Element) (Nodes, error)
- func NewULNodes(p *Parser, el *Element) (Nodes, error)
- func NewVarNodes(p *Parser, el *Element) (Nodes, error)
- func ToNodes[T Node](list []T) Nodes
- func (list Nodes) Children() Nodes
- func (list Nodes) Delete(node Node) Nodes
- func (list Nodes) Execute(wg WaitGrouper, ctx context.Context, d *Document) (err error)
- func (list Nodes) Format(f fmt.State, verb rune)
- func (list Nodes) MD() string
- func (list Nodes) PostExecute(ctx context.Context, d *Document, err error) error
- func (list Nodes) PostParse(p *Parser, d *Document, err error) error
- func (list Nodes) PreExecute(ctx context.Context, d *Document) error
- func (list Nodes) String() string
- type Now
- type OL
- type Page
- type Paragraph
- type ParseElementFn
- type ParseError
- type Parser
- func (p *Parser) MarshalJSON() ([]byte, error)
- func (p *Parser) Now() time.Time
- func (p *Parser) Parse(r io.Reader) (doc *Document, err error)
- func (p *Parser) ParseExecute(ctx context.Context, r io.Reader) (*Document, error)
- func (p *Parser) ParseExecuteFile(ctx context.Context, name string) (*Document, error)
- func (p *Parser) ParseExecuteFolder(ctx context.Context, name string) (Documents, error)
- func (p *Parser) ParseExecuteFragment(ctx context.Context, r io.Reader) (Nodes, error)
- func (p *Parser) ParseFile(name string) (doc *Document, err error)
- func (p *Parser) ParseFolder(name string) (doc Documents, err error)
- func (p *Parser) ParseFragment(r io.Reader) (Nodes, error)
- func (p *Parser) ParseHTMLNode(node *html.Node, parent Node) (Node, error)
- func (p *Parser) Sub(dir string) (*Parser, error)
- type PostExecuteError
- type PostExecuteFn
- type PostExecuter
- type PostParseError
- type PostParseFn
- type PostParser
- type PreExecuteError
- type PreExecuteFn
- type PreExecuter
- type PreParseError
- type PreParseFn
- type PreParser
- type PreParsers
- type Ref
- type RefProcessor
- type Snippet
- type Snippets
- func (sm *Snippets) Add(ext string, rule string)
- func (sm *Snippets) Get(name string) (map[string]Snippet, bool)
- func (sm *Snippets) MarshalJSON() ([]byte, error)
- func (sm *Snippets) Parse(path string, src []byte) (map[string]Snippet, error)
- func (sm *Snippets) TrimComments(path string, src []byte) ([]byte, error)
- func (sm *Snippets) UnmarshalJSON(data []byte) error
- type SourceCode
- type TD
- type TH
- type THead
- type TR
- type Table
- type Tag
- type Tags
- type Text
- type ToC
- type UL
- type Var
- type WaitGrouper
Constants ¶
const (
ErrNilFigure = ErrIsNil("figure")
)
const (
TIME_FORMAT = "2006-01-02 15:04:05 -0700 MST"
)
Variables ¶
This section is empty.
Functions ¶
func AttrMatches ¶
func AttrMatches(ats *Attributes, query map[string]string) bool
AttrMatches returns true if the given keys and values in the query map are present, and equal, in the given attributes. A `*` matches any value.
func DefaultElements ¶
func DefaultElements() map[Atom]ParseElementFn
DefaultElements returns a map of all the default element parser functions. For example, `include`, `body`, `code`, etc.
func FindTitle ¶
FindTitle finds the title element in the given HTML document. If no title element is found, the first h1 element is returned. If no h1 element is found, `"Untitled"` is returned.
func FirstByType ¶
func IsEmptyNode ¶
func Language ¶
func Language(ats *Attributes, lang string) string
Language tries to determine the language of the given set of attributes.
- "language" is the first attr tested.
- "language-*" is the second attr tested. (e.g. "language-go", "language-js")
- "lang" is the third attr tested.
func RestripeFigureIDs ¶
func RestripeFigureIDs(nodes Nodes, fn IDGenerator) error
RestripeFigureIDs will rewrite all of the figure IDs, and they're references, using the given IDGenerator.
func WrapNodeErr ¶
Types ¶
type AtomableNode ¶
func ByAtom ¶
func ByAtom[T ~string](nodes Nodes, want ...T) []AtomableNode
func FirstByAtom ¶
func FirstByAtom[T ~string](nodes Nodes, want ...T) (AtomableNode, bool)
type AttrNode ¶
type AttrNode interface {
Node
Attrs() *Attributes
}
type Attributes ¶
func ConvertHTMLAttrs ¶
func ConvertHTMLAttrs(attrs []html.Attribute) (*Attributes, error)
ConvertHTMLAttrs converts a slice of HTML attributes to a new Attributes type.
type Body ¶
type Body struct {
*Element
}
Body is a container for all the elements in a document.
func (*Body) MarshalJSON ¶
type Cmd ¶
type Cmd struct {
*Element
Args []string
Env []string
ExpectedExit int
Timeout time.Duration
// contains filtered or unexported fields
}
Cmd is a tag representing a command to be executed.
func (*Cmd) MarshalJSON ¶
type CmdError ¶
func (CmdError) MarshalJSON ¶
type Document ¶
type Document struct {
fs.FS
sync.RWMutex
ID string
Nodes Nodes
Parser *Parser // Parser used to create the document
Root string
SectionID int
Snippets Snippets
Title string
Filename string
}
func (*Document) Execute ¶
Execute the Document with the given context. Any child nodes that implement the PreExecuter, ExecutableNode, or PostExecuter interfaces will be executed.
func (*Document) MarshalJSON ¶
type Element ¶
type Element struct {
*Attributes
sync.RWMutex
HTMLNode *html.Node
Nodes Nodes
Parent Node
Filename string // only set when Parser.ParseFile() is used
}
func (*Element) Attrs ¶
func (el *Element) Attrs() *Attributes
func (*Element) EndTag ¶
EndTag returns the end tag for the element. For example, for an element with an Atom of "div", the end tag would be "</div>".
func (*Element) FileName ¶
FileName returns the filename of the element. This is only set when Parser.ParseFile() is used.
func (*Element) MarshalJSON ¶
func (*Element) StartTag ¶
StartTag returns the start tag for the element. For example, for an element with an Atom of "div", the start tag would be "<div>".
type EmptyableNode ¶
type EmptyableNode interface {
IsEmptyNode() bool
}
type ErrAttrEmpty ¶
type ErrAttrEmpty string
func (ErrAttrEmpty) Error ¶
func (e ErrAttrEmpty) Error() string
type ErrAttrNotFound ¶
type ErrAttrNotFound string
func (ErrAttrNotFound) Error ¶
func (e ErrAttrNotFound) Error() string
type ExecutableNode ¶
type ExecuteError ¶
type ExecuteError struct {
Err error
Contents []byte
Document *Document
Filename string
Root string
}
func (ExecuteError) As ¶
func (pe ExecuteError) As(target any) bool
func (ExecuteError) Error ¶
func (pe ExecuteError) Error() string
func (ExecuteError) Is ¶
func (pe ExecuteError) Is(target error) bool
func (ExecuteError) MarshalJSON ¶
func (pe ExecuteError) MarshalJSON() ([]byte, error)
func (ExecuteError) String ¶
func (pe ExecuteError) String() string
func (ExecuteError) Unwrap ¶
func (pe ExecuteError) Unwrap() error
type FencedCode ¶
type FencedCode struct {
*Element
}
func NewFencedCode ¶
func NewFencedCode(el *Element) (*FencedCode, error)
func (*FencedCode) Lang ¶
func (code *FencedCode) Lang() string
func (*FencedCode) MD ¶
func (code *FencedCode) MD() string
func (*FencedCode) MarshalJSON ¶
func (code *FencedCode) MarshalJSON() ([]byte, error)
type Figcaption ¶
type Figcaption struct {
*Element
}
func NewFigcaption ¶
func NewFigcaption(el *Element) (*Figcaption, error)
func (*Figcaption) MD ¶
func (fc *Figcaption) MD() string
func (*Figcaption) MarshalJSON ¶
func (fc *Figcaption) MarshalJSON() ([]byte, error)
type Figure ¶
func (*Figure) MarshalJSON ¶
type Heading ¶
type Heading struct {
*Element
// contains filtered or unexported fields
}
func NewHeading ¶
func (*Heading) MarshalJSON ¶
type Include ¶
type Include struct {
*Element
// contains filtered or unexported fields
}
func (*Include) MarshalJSON ¶
type InlineCode ¶
type InlineCode struct {
*Element
}
func NewInlineCode ¶
func NewInlineCode(el *Element) (*InlineCode, error)
func (*InlineCode) MD ¶
func (code *InlineCode) MD() string
func (*InlineCode) MarshalJSON ¶
func (code *InlineCode) MarshalJSON() ([]byte, error)
func (*InlineCode) String ¶
func (code *InlineCode) String() string
type LI ¶
func (*LI) MarshalJSON ¶
type Nodes ¶
type Nodes []Node
func NewBodyNodes ¶
NewBodyNodes implements the ParseElementFn type
func NewCodeNodes ¶
NewCodeNodes implements the ParseElementFn type
func NewIncludeNodes ¶
NewIncludeNodes implements the ParseElementFn type
func (Nodes) PostExecute ¶
type Page ¶
func (*Page) MarshalJSON ¶
type Paragraph ¶
type Paragraph struct {
*Element
}
func (*Paragraph) IsEmptyNode ¶
func (*Paragraph) MarshalJSON ¶
type ParseError ¶
func (ParseError) As ¶
func (pe ParseError) As(target any) bool
func (ParseError) Error ¶
func (pe ParseError) Error() string
func (ParseError) Is ¶
func (pe ParseError) Is(target error) bool
func (ParseError) MarshalJSON ¶
func (pe ParseError) MarshalJSON() ([]byte, error)
func (ParseError) Unwrap ¶
func (pe ParseError) Unwrap() error
type Parser ¶
type Parser struct {
fs.FS
DisablePages bool
DocIDGen func() (string, error) // default: uuid.NewV4().String()
Filename string // only set when Parser.ParseFile() is used
NodeParsers map[Atom]ParseElementFn
NowFn func() time.Time // default: time.Now()
PreParsers PreParsers
Root string
Section int
Vars syncx.Map[string, any]
Contents []byte // a copy of the contents being parsed - set just before parsing
// contains filtered or unexported fields
}
func NewParser ¶
NewParser returns a fully initialized Parser. This includes the Markdown pre-parser and the default node parsers.
func (*Parser) MarshalJSON ¶
func (*Parser) ParseExecute ¶
func (*Parser) ParseExecuteFile ¶
func (*Parser) ParseExecuteFolder ¶
func (*Parser) ParseExecuteFragment ¶
func (*Parser) ParseFile ¶
ParseFile parses the given file from Parser.FS. If successful a *Document is returned. The returned *Document is NOT yet executed.
func (*Parser) ParseHTMLNode ¶
type PostExecuteError ¶
type PostExecuteError struct {
Err error
Document *Document
Filename string
OrigErr error
Root string
PostExecuter any
}
func (PostExecuteError) As ¶
func (e PostExecuteError) As(target any) bool
func (PostExecuteError) Error ¶
func (e PostExecuteError) Error() string
func (PostExecuteError) Is ¶
func (e PostExecuteError) Is(target error) bool
func (PostExecuteError) MarshalJSON ¶
func (pee PostExecuteError) MarshalJSON() ([]byte, error)
func (PostExecuteError) Unwrap ¶
func (e PostExecuteError) Unwrap() error
type PostExecuteFn ¶
func (PostExecuteFn) PostExecute ¶
type PostExecuter ¶
type PostParseError ¶
type PostParseError struct {
Err error
Document *Document
Filename string
OrigErr error
Root string
PostParser any
}
func (PostParseError) As ¶
func (ppe PostParseError) As(target any) bool
func (PostParseError) Error ¶
func (ppe PostParseError) Error() string
func (PostParseError) Is ¶
func (ppe PostParseError) Is(target error) bool
func (PostParseError) MarshalJSON ¶
func (ppe PostParseError) MarshalJSON() ([]byte, error)
func (PostParseError) Unwrap ¶
func (ppe PostParseError) Unwrap() error
type PostParseFn ¶
type PreExecuteError ¶
type PreExecuteError struct {
Err error
Document *Document
Filename string
Root string
PreExecuter any
}
func (PreExecuteError) As ¶
func (pee PreExecuteError) As(target any) bool
func (PreExecuteError) Error ¶
func (pee PreExecuteError) Error() string
func (PreExecuteError) Is ¶
func (pee PreExecuteError) Is(target error) bool
func (PreExecuteError) MarshalJSON ¶
func (pee PreExecuteError) MarshalJSON() ([]byte, error)
func (PreExecuteError) Unwrap ¶
func (pee PreExecuteError) Unwrap() error
type PreExecuteFn ¶
func (PreExecuteFn) PreExecute ¶
func (fn PreExecuteFn) PreExecute(ctx context.Context, d *Document) error
type PreExecuter ¶
type PreParseError ¶
func (PreParseError) As ¶
func (e PreParseError) As(target any) bool
func (PreParseError) Error ¶
func (e PreParseError) Error() string
func (PreParseError) Is ¶
func (e PreParseError) Is(target error) bool
func (PreParseError) MarshalJSON ¶
func (e PreParseError) MarshalJSON() ([]byte, error)
func (PreParseError) Unwrap ¶
func (e PreParseError) Unwrap() error
type PreParseFn ¶
func GoTemplates ¶
func GoTemplates() PreParseFn
func Markdown ¶
func Markdown() PreParseFn
func VarProcessor ¶
func VarProcessor() PreParseFn
type PreParsers ¶
type PreParsers []PreParser
type Ref ¶
func (*Ref) MarshalJSON ¶
type RefProcessor ¶
type RefProcessor struct {
IDGenerator IDGenerator
// contains filtered or unexported fields
}
func (*RefProcessor) CurIndex ¶
func (rp *RefProcessor) CurIndex(key string) int
CurIndex will return the current index for the given key.
func (*RefProcessor) NextIndex ¶
func (rp *RefProcessor) NextIndex(key string) int
NextIndex will increment the index for the given key, and return the new index.
func (*RefProcessor) Process ¶
func (rp *RefProcessor) Process(doc *Document) error
func (*RefProcessor) ProcessFigure ¶
func (rp *RefProcessor) ProcessFigure(sectionID int, fig *Figure) error
type Snippet ¶
type Snippet struct {
Content string `json:"content,omitempty"` // The content of the snippet
File string `json:"file,omitempty"` // the file name of the snippet
Lang string `json:"lang,omitempty"` // the language of the snippet
Name string `json:"name,omitempty"` // the name of the snippet
Start int `json:"start,omitempty"` // the start line of the snippet
End int `json:"end,omitempty"` // the end line of the snippet
}
func (*Snippet) MarshalJSON ¶
type Snippets ¶
type Snippets struct {
// contains filtered or unexported fields
}
func (*Snippets) MarshalJSON ¶
func (*Snippets) TrimComments ¶
func (*Snippets) UnmarshalJSON ¶
type SourceCode ¶
func (*SourceCode) Execute ¶
func (code *SourceCode) Execute(ctx context.Context, d *Document) error
func (*SourceCode) MD ¶
func (code *SourceCode) MD() string
func (*SourceCode) MarshalJSON ¶
func (code *SourceCode) MarshalJSON() ([]byte, error)
func (*SourceCode) String ¶
func (code *SourceCode) String() string
type Var ¶
func (*Var) MarshalJSON ¶
type WaitGrouper ¶
type WaitGrouper interface {
Go(fn func() error)
}
Source Files
¶
- atom.go
- attributes.go
- body.go
- cmd.go
- cmd_error.go
- cmd_result.go
- code.go
- comment.go
- document.go
- element.go
- empty.go
- errors.go
- execute.go
- execute_error.go
- fenced_code.go
- figcaption.go
- figure.go
- finders.go
- godoc.go
- golang.go
- heading.go
- home.go
- hype.go
- image.go
- include.go
- inline_code.go
- li.go
- link.go
- md.go
- metadata.go
- node.go
- now.go
- ol.go
- page.go
- paragraph.go
- parse_error.go
- parser.go
- post_execute.go
- post_execute_error.go
- post_parse_error.go
- post_parser.go
- pre_execute.go
- pre_execute_error.go
- pre_parse_error.go
- pre_parser.go
- ref.go
- ref_processor.go
- restripe_figures.go
- snippet.go
- source_code.go
- table.go
- tag.go
- td.go
- text.go
- th.go
- thead.go
- time.go
- title.go
- tmpl.go
- toc.go
- tr.go
- type.go
- ul.go
- unwrap.go
- var.go
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
hype
command
|
|
|
docs
|
|
|
quickstart/src/broken
command
|
|
|
quickstart/src/hello
command
|
|
|
internal
|
|