templ

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 4 Imported by: 0

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

View Source
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 Parse

func Parse(filename string) (*syntax.Node, error)

Parse parses the given templ file and returns the unified syntax tree.

func ParseBytes

func ParseBytes(filename string, content []byte) (*syntax.Node, int, error)

ParseBytes parses templ content and returns the syntax tree along with the line count.

func ParseWithLineCount

func ParseWithLineCount(filename string) (*syntax.Node, int, error)

ParseWithLineCount parses the given templ file and returns the syntax tree along with the line count.

Types

This section is empty.

Jump to

Keyboard shortcuts

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