Documentation
¶
Overview ¶
Package atomdown parses and validates persistent block IDs, ordered groups, and extensible XML-shaped metadata embedded in ordinary Markdown comments. Atomdown documents remain valid CommonMark and visible Markdown remains the source of truth.
Index ¶
- func Materialize(source []byte) ([]byte, error)
- func NewID() (string, error)
- func NormalizedXML(document Document) ([]byte, error)
- func Strip(source []byte) []byte
- type Atom
- type AtomGroup
- type Attribute
- type Diagnostic
- type DirectiveToken
- type Document
- type Extension
- type ExtensionFunc
- type Position
- type Processor
- type Range
- type Severity
- type Token
- type TokenKind
- type TokenStream
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Materialize ¶
Materialize inserts an explicit atom marker before every implicit atom. Existing source bytes and explicit directives remain unchanged.
func NormalizedXML ¶
NormalizedXML returns the Atomdown metadata model as a conventional XML document. Markdown content remains in the source file and is represented by atom IDs.
Types ¶
type Atom ¶
type Atom struct {
ID string `json:"id,omitempty"`
Slug string `json:"slug,omitempty"`
Attributes []Attribute `json:"attributes,omitempty"`
Marker *Range `json:"marker,omitempty"`
Content Range `json:"content"`
NodeType string `json:"nodeType"`
Text string `json:"text"`
Implicit bool `json:"implicit"`
GroupID string `json:"groupId,omitempty"`
}
Atom is one explicit or implicit top-level Markdown unit.
type AtomGroup ¶
type AtomGroup struct {
ID string `json:"id"`
Slug string `json:"slug,omitempty"`
Attributes []Attribute `json:"attributes,omitempty"`
Marker Range `json:"marker"`
EndMarker *Range `json:"endMarker,omitempty"`
AtomIDs []string `json:"atomIds,omitempty"`
}
AtomGroup is a contiguous, ordered collection of explicit atoms.
type Diagnostic ¶
type Diagnostic struct {
Code string `json:"code"`
Severity Severity `json:"severity"`
Message string `json:"message"`
Position Position `json:"position"`
Fix string `json:"fix,omitempty"`
}
Diagnostic describes a syntax or semantic defect.
type DirectiveToken ¶
type DirectiveToken struct {
Element string `json:"element"`
Operation string `json:"operation"`
ID string `json:"id,omitempty"`
Slug string `json:"slug,omitempty"`
Version string `json:"version,omitempty"`
Attributes []Attribute `json:"attributes,omitempty"`
}
DirectiveToken is the public XML-shaped view of an Atomdown directive.
type Document ¶
type Document struct {
Declared bool `json:"declared"`
Version string `json:"version,omitempty"`
Attributes []Attribute `json:"attributes,omitempty"`
Atoms []Atom `json:"atoms"`
Groups []AtomGroup `json:"groups,omitempty"`
Diagnostics []Diagnostic `json:"diagnostics,omitempty"`
}
Document is the parsed Atomdown view of a Markdown source file.
type Extension ¶
Extension adds application-specific behavior to the parsed document model. Extensions run in registration order and may decorate the document, preserve private state in attributes, or append extension-specific diagnostics.
type ExtensionFunc ¶
type ExtensionFunc struct {
ExtensionName string
TransformFunc func(context.Context, []byte, *Document) error
}
ExtensionFunc adapts a function into an Extension.
func (ExtensionFunc) Name ¶
func (extension ExtensionFunc) Name() string
Name returns the extension's stable name.
type Position ¶
type Position struct {
Offset int `json:"offset"`
Line int `json:"line"`
Column int `json:"column"`
}
Position identifies a byte offset and its one-based line and column.
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
Processor parses Atomdown and applies embedded extensions.
func NewProcessor ¶
NewProcessor creates an embedded Atomdown processor.
type Token ¶
type Token struct {
Kind TokenKind `json:"kind"`
Range Range `json:"range"`
Raw string `json:"raw"`
NodeType string `json:"nodeType,omitempty"`
Directive *DirectiveToken `json:"directive,omitempty"`
}
Token is one lossless Markdown, whitespace, or Atomdown source segment. Concatenating Raw for every token reconstructs the original document.
type TokenStream ¶
type TokenStream struct {
Tokens []Token `json:"tokens"`
Diagnostics []Diagnostic `json:"diagnostics,omitempty"`
}
TokenStream contains a lossless ordered source stream and lexical diagnostics.
func Tokenize ¶
func Tokenize(source []byte) TokenStream
Tokenize returns a lossless ordered stream containing Markdown blocks, Atomdown directives, and interstitial whitespace.