Documentation
¶
Overview ¶
gomd package contains the core functionality for parsing and building a markup document tree using a pluggable engine system. It defines the Engine interface, the Runner struct for executing the parsing and building process, and functions for tagging lines, cleaning tags, and constructing a tree from tags. The plugin system allows for extensions to provide custom parsing rules and node builders, enabling flexible and extensible markup processing. The process involves two main steps:
- Tagging: The input content is read and processed line by line and character by character to generate a series of tags based on the rules defined by the extensions.
- Building: The generated tags are then used to construct a tree structure representing the markup document, using node builders provided by the extensions.
Each extension should implement the Extension interface to provide its own parsing rules and node builders:
- CharTaggingRuleSet: Returns a set of character-level tagging rules.
- LineTaggingRuleSet: Returns a set of line-level tagging rules.
- TagCleaner: Returns a function to clean or modify the generated tags.
- NodeBuilders: Returns a set of node builders for constructing the tree.
Basic example of a extension workflow:
- The extension defines its tagging rules and node builders.
- In the tagging phase, the Runner applies the line and character tagging rules to the input content to generate tags. The extension's rules will receive lines and characters to tag accordingly. These rules should check if the content receives matches their criteria and return the appropriate tags, or skip if not.
- After tagging, the Runner applies the TagCleaner function from the extension to clean or modify the generated tags as needed. It could be used to remove redundant tags, merge adjacent tags, or perform any other necessary adjustments before building the tree.
- In the building phase, the Runner uses the node builders provided by the extension to construct the tree structure from the cleaned tags. Each node builder will attempt to decode tags into tree nodes based on the extension's logic. The extension can use the BuildTree function to generate child subtrees recursively using the extension builders. It should skip those tags that it cannot decode.
Index ¶
- func BuildChilds(node *tree.Node, decoders types.NodeBuildersSet[*types.Tag], tags []*types.Tag) (*tree.Node, error)
- func EncodeChilds(node *tree.Node, encoders types.NodeEncodersSet) ([]byte, error)
- type Engine
- type Runner
- func (r *Runner) CharTaggingRuleSet() types.CharTaggingRuleSet
- func (r *Runner) Decode(in io.Reader) (*tree.Node, error)
- func (r *Runner) DecodeBytes(content []byte) (*tree.Node, error)
- func (r *Runner) Encode(node *tree.Node) ([]byte, error)
- func (r *Runner) LineTaggingRuleSet() types.LineTaggingRuleSet
- func (r *Runner) NodeBuilders() types.NodeBuildersSet[*types.Tag]
- func (r *Runner) NodeEncoders() types.NodeEncodersSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildChilds ¶ added in v0.0.2
func BuildChilds( node *tree.Node, decoders types.NodeBuildersSet[*types.Tag], tags []*types.Tag, ) (*tree.Node, error)
BuildChilds constructs a tree.Node from the provided root node, decoders, and tags. It iterates over the tags and applies the decoders to build the tree under the root node. It returns an error if any decoding fails or if tags cannot be decoded.
func EncodeChilds ¶ added in v0.0.2
EncodeChilds encodes the child nodes of the provided tree.Node using the provided encoders. It returns a byte slice representing the encoded content or an error if encoding fails or if no encoder is found for a child node.
Types ¶
type Engine ¶
Engine defines the interface for a markup engine. It provides methods to retrieve extensions and the default tag.
type Runner ¶
type Runner struct {
Engine
}
Runner is responsible for running the tagging and building process using a given Engine.
func (*Runner) CharTaggingRuleSet ¶
func (r *Runner) CharTaggingRuleSet() types.CharTaggingRuleSet
func (*Runner) Decode ¶
Decode reads from the provided io.Reader, tags the content, and builds a tree.Node representation of the content. It returns an error if reading, tagging, or building fails.
func (*Runner) DecodeBytes ¶
DecodeBytes tags the provided byte content and builds a tree.Node representation of the content. It returns an error if tagging or building fails.
func (*Runner) Encode ¶ added in v0.0.2
Encode encodes the provided tree.Node into a byte slice. It returns an error if encoding fails or if the node is not a root node. It uses current extension node encoders to perform the encoding.
func (*Runner) LineTaggingRuleSet ¶
func (r *Runner) LineTaggingRuleSet() types.LineTaggingRuleSet
func (*Runner) NodeBuilders ¶
func (r *Runner) NodeBuilders() types.NodeBuildersSet[*types.Tag]
func (*Runner) NodeEncoders ¶ added in v0.0.2
func (r *Runner) NodeEncoders() types.NodeEncodersSet
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
markdow2json
command
|
|
|
engines
|
|
|
iterator package contains a generic thread-safe iterator for slices of any type T. It provides methods for navigating through a collection of items, iterating over them or filtering based on certain conditions.
|
iterator package contains a generic thread-safe iterator for slices of any type T. It provides methods for navigating through a collection of items, iterating over them or filtering based on certain conditions. |
|
tree package contains the Node structure and related types and methods that allows to represent a document as a tree of nodes ("pieces") of content.
|
tree package contains the Node structure and related types and methods that allows to represent a document as a tree of nodes ("pieces") of content. |