html

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetIndentConfig

func SetIndentConfig(config IndentConfig)

SetIndentConfig updates the global indentation configuration.

func TraverseNode

func TraverseNode(n NodeList, f func(*ElementNode))

Types

type Attribute

type Attribute struct {
	Key   string
	Value string
}

Attribute represents an HTML attribute with key and value.

func (Attribute) Dump

func (a Attribute) Dump(indent int) string

type AttributeEntityEncodingFromTo

type AttributeEntityEncodingFromTo struct {
	From string
	To   string
}

type CommentNode

type CommentNode struct {
	Text string
	Line int
}

CommentNode represents an HTML comment.

func (*CommentNode) Dump

func (c *CommentNode) Dump(indent int) string

Dump returns the comment text with HTML comment syntax.

type ConfiguredNodeList

type ConfiguredNodeList struct {
	Nodes  NodeList
	Config IndentConfig
}

ConfiguredNodeList wraps a NodeList with its associated IndentConfig

func NewAdminParser

func NewAdminParser(input string) (ConfiguredNodeList, error)

NewAdminParser creates a parser configured for admin twig files (no indentation for twig block children).

func NewFrontendParser added in v0.0.3

func NewFrontendParser(input string) (ConfiguredNodeList, error)

NewFrontendParser creates a parser configured for frontend twig files (indents twig block children).

func (ConfiguredNodeList) Dump

func (cnl ConfiguredNodeList) Dump(indent int) string

Dump renders the nodes using the stored configuration

type ElementNode

type ElementNode struct {
	Tag         string
	Attributes  NodeList
	Children    NodeList
	SelfClosing bool
	Line        int // added field
}

ElementNode represents an HTML element.

func (*ElementNode) Dump

func (e *ElementNode) Dump(indent int) string

Dump returns the HTML representation of the element and its children.

type IndentConfig

type IndentConfig struct {
	SpaceIndent             bool
	IndentSize              int
	TwigBlockIndentChildren bool
}

IndentConfig holds configuration for indentation in HTML output.

func DefaultIndentConfig

func DefaultIndentConfig() IndentConfig

DefaultIndentConfig creates a default indentation config with spaces.

func (IndentConfig) GetIndent

func (c IndentConfig) GetIndent() string

GetIndent returns the indentation string based on configuration.

type Node

type Node interface {
	Dump(indent int) string
}

Node is the interface for nodes in our AST.

type NodeList

type NodeList []Node

func NewParser

func NewParser(input string) (NodeList, error)

NewParser creates a new parser for the given input.

func NewParserWithConfig

func NewParserWithConfig(input string, config IndentConfig) (NodeList, error)

NewParserWithConfig creates a new parser with a specific indentation configuration.

func (NodeList) Dump

func (nodeList NodeList) Dump(indent int) string

type ParentNode

type ParentNode struct {
	Line int
}

ParentNode represents a twig parent() call

func (*ParentNode) Dump

func (p *ParentNode) Dump(indent int) string

type Parser

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

Parser holds the state for our simple parser.

type RawNode

type RawNode struct {
	Text string
	Line int // added field
}

RawNode holds unchanged text.

func (*RawNode) Dump

func (r *RawNode) Dump(indent int) string

Dump returns the raw text.

type TemplateExpressionNode

type TemplateExpressionNode struct {
	Expression string
	Line       int
}

TemplateExpressionNode represents a {{...}} template expression.

func (*TemplateExpressionNode) Dump

func (t *TemplateExpressionNode) Dump(indent int) string

Dump returns the template expression with {{ }} delimiters.

type TwigBlockNode

type TwigBlockNode struct {
	Name     string
	Children NodeList
	Line     int
}

TwigBlockNode represents a twig block.

func (*TwigBlockNode) Dump

func (t *TwigBlockNode) Dump(indent int) string

Dump returns the twig block with proper formatting.

type TwigIfNode

type TwigIfNode struct {
	Condition        string
	Children         NodeList
	ElseIfConditions []string
	ElseIfChildren   []NodeList
	ElseChildren     NodeList
	Line             int
}

TwigIfNode represents a Twig if block

func (*TwigIfNode) Dump

func (t *TwigIfNode) Dump(indent int) string

Dump returns the twig if block with proper formatting

Jump to

Keyboard shortcuts

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