transformer

package
v0.4.0-beta.27 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EnvMatcher = regexp.MustCompile(`(\$[A-Z0-9_]+)`)

Functions

func AppendChild

func AppendChild(parent goldast.Node, child goldast.Node)

func ConvertTextForSubenv

func ConvertTextForSubenv(node goldast.Node, reader goldtext.Reader, treatments *Treatment)

func ConvertToRundownNode

func ConvertToRundownNode(node *ast.RundownBlock, reader goldtext.Reader) (goldast.Node, error)

Converts a RundownBlock into a proper instruction node. Returns the node to continue iterating from, or an error.

func DissolveRundownBlock

func DissolveRundownBlock(block goldast.Node)

Deletes a rundown block, moving it's children into it's parent.

func FindEndOfSection

func FindEndOfSection(startNode *goldast.Heading) goldast.Node

Given the startNode (being the section node itself), returns the last node of the section. Called after the section has been inserted into the AST, but before children have been moved into it.

func NewRundownASTTransformer

func NewRundownASTTransformer() *rundownASTTransformer

Rundown AST Transformer converts Rundown Elements in the markdown tree into proper rundown nodes, and applies any effects.

func PopulateSectionMetadata

func PopulateSectionMetadata(start *ast.SectionPointer, reader goldtext.Reader)

func Remove

func Remove(nodeToRemove goldast.Node, reader goldtext.Reader) goldast.Node

Remove a node. Returns what next node after this node is removed.

func Replace

func Replace(nodeToReplace goldast.Node, replacement goldast.Node)

func ReplaceWithChildren

func ReplaceWithChildren(nodeToReplace goldast.Node, replacement goldast.Node, nodeWithChildren goldast.Node)

Replaces the node, and adds children to it from the given node.

Types

type GatherProcessor

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

func NewGatherProcessor

func NewGatherProcessor(replacingNode goldast.Node, newNode goldast.Node) *GatherProcessor

Gathers nodes directly descending from replacingNode and putting them into newNode. If newNode is nil, then replacingNode and all children are deleted instead.

func (*GatherProcessor) Begin

func (p *GatherProcessor) Begin(openingTag *RundownHtmlTag)

func (*GatherProcessor) End

func (p *GatherProcessor) End(node goldast.Node, reader goldtext.Reader, openingTag *RundownHtmlTag, treatments *Treatment) bool

func (*GatherProcessor) Process

func (p *GatherProcessor) Process(node goldast.Node, reader goldtext.Reader, treatments *Treatment) bool

type NodeProcessor

type NodeProcessor interface {
	Begin(openingTag *ast.RundownBlock)

	// Process a Markdown Node. Returns true to indicate the processor is done and should be removed.
	Process(node goldast.Node, reader goldtext.Reader, treatments *Treatment) bool

	// Indicates to the processor it should end itself.
	End(node goldast.Node, reader goldtext.Reader, treatments *Treatment)
}

NodeProcessors allow us to apply effects to subsequent nodes or "child" nodes of a Rundown tag.

type OpenTags

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

type RundownHtmlTag

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

func ExtractRundownElement

func ExtractRundownElement(node goldast.Node, reader goldtext.Reader, currentTag string) []*RundownHtmlTag

type SubEnvProcessor

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

SubEnv Processor replaces all mentions of $ENV_VAR with a EnvironmentSubstitution node.

func (*SubEnvProcessor) Begin

func (p *SubEnvProcessor) Begin(node *ast.RundownBlock)

func (*SubEnvProcessor) End

func (p *SubEnvProcessor) End(node goldast.Node, reader goldtext.Reader, treatments *Treatment) bool

func (*SubEnvProcessor) Process

func (p *SubEnvProcessor) Process(node goldast.Node, reader goldtext.Reader, treatments *Treatment) bool

type Treatment

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

Treatment is used to indicate a node should be modified, but batches these modifications for after we've walked the AST, otherwise the walker gets confused.

func NewTreatment

func NewTreatment(reader goldtext.Reader) *Treatment

func (*Treatment) AppendChild

func (t *Treatment) AppendChild(parent goldast.Node, child goldast.Node)

func (*Treatment) DissolveRundownBlock

func (t *Treatment) DissolveRundownBlock(block goldast.Node)

Deletes a rundown block, moving it's children into it's parent.

func (*Treatment) Ignore

func (t *Treatment) Ignore(nodeToIgnore goldast.Node)

func (*Treatment) IsIgnored

func (t *Treatment) IsIgnored(nodeInQuestion goldast.Node) bool

func (*Treatment) NewNodes

func (t *Treatment) NewNodes() []goldast.Node

Returns the newly added nodes since the last call.

func (*Treatment) Process

func (t *Treatment) Process(reader goldtext.Reader)

func (*Treatment) Remove

func (t *Treatment) Remove(nodeToRemove goldast.Node) goldast.Node

Remove a node. Returns what the next node will be after this node is removed.

func (*Treatment) Replace

func (t *Treatment) Replace(nodeToReplace goldast.Node, replacement goldast.Node)

func (*Treatment) ReplaceWithChildren

func (t *Treatment) ReplaceWithChildren(nodeToReplace goldast.Node, replacement goldast.Node, nodeWithChildren goldast.Node)

Replaces the node, and adds children to it from the given node.

Jump to

Keyboard shortcuts

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