Documentation
¶
Overview ¶
Package templ provides AST parsing for templ files using the official templ parser. It transforms templ template syntax into unified syntax.Node for clone detection.
We focus on structural elements: declarations, HTML elements, flow control, attributes. We skip: text content, attribute values, identifiers.
Index ¶
- Constants
- func Parse(filename string) (*syntax.Node, error)
- func ParseBytes(filename string, content []byte) (*syntax.Node, int, error)
- func ParseBytesWithMode(filename string, content []byte, semantic bool) (*syntax.Node, int, error)
- func ParseWithLineCount(filepath string) (*syntax.Node, int, error)
- func ParseWithLineCountWithMode(filepath string, semantic bool) (*syntax.Node, int, error)
Constants ¶
const ( BadNode = iota // ComponentDeclaration represents a component declaration. ComponentDeclaration CSSDeclaration ScriptDeclaration // Element represents an HTML element. Element TagStart TagEnd SelfClosingTag Doctype // StyleElement represents a style element (structural, not content). StyleElement ScriptElement // ComponentIfStatement represents a component if statement. ComponentIfStatement ComponentForStatement ComponentSwitchStatement ComponentSwitchExpressionCase ComponentSwitchDefaultCase // Attribute represents an attribute (structural). Attribute SpreadAttributes ConditionalAttributeIfStatement // Expression represents an expression or block. Expression ComponentBlock ComponentRender ComponentChildrenExpression RawGoBlock // ComponentImport represents an import. ComponentImport // File represents the file root. File )
Node type constants for templ syntax. Meaningful types capture structure without content.
Variables ¶
This section is empty.
Functions ¶
func ParseBytes ¶
ParseBytes parses templ content and returns the syntax tree along with the line count.
func ParseBytesWithMode ¶ added in v0.4.0
ParseBytesWithMode parses templ content with optional semantic encoding. When semantic is true, element tag names and attribute names are encoded into node Types, so <a href> and <div class> produce different tokens.
func ParseWithLineCount ¶
ParseWithLineCount parses the given templ file and returns the syntax tree along with the line count.
Types ¶
This section is empty.