Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse error with templ elements #86

Closed
diamondburned opened this issue May 8, 2023 · 5 comments
Closed

parse error with templ elements #86

diamondburned opened this issue May 8, 2023 · 5 comments

Comments

@diamondburned
Copy link

diamondburned commented May 8, 2023

The following snippet:

templ x() {
	<li>
		<a href="/">
			Home
			@Icon("home", Inline)
		</a>
	</li>
}

gets formatted to become:

templ x() {
	<li><a href="/">
	Home
	@Icon("home", Inline)
</a></li>
}

I don't think this is expected behavior.

Even worse, this code:

templ x() {
	<li><a href="/"> @Icon("home", Inline) Home</a></li>
}

actually just errors out completely with a parsing error:

parsing error: <a>: expected end tag not present or invalid tag contents: line 2, col 0
@a-h
Copy link
Owner

a-h commented May 8, 2023

Thanks for trying out templ, and for the issue report. 😁

I'd assumed that using the templ element expression (@Icon syntax) would represent block level elements, hence which is the root cause of this.

This is two related issues. I'll move the formatting one into its own issue, and resolve this one as the parsing error.

I've added a commit for this issue at c160cc4 - the unit test on that commit includes your example.

@a-h a-h changed the title templ fmt indents weirdly if @component is put before/after text parse error with templ elements May 8, 2023
@a-h
Copy link
Owner

a-h commented May 8, 2023

Please take a look at #87 too. I've added a commit for that too.

@diamondburned
Copy link
Author

7efc71c seems to break my layouts function, which goes something like

templ x() {
	@layouts.Main("", site, owner, layouts.MainOpts{Me: opts.Me}) {
		<main id="index">
		</main>
	}
}

templ couldn't seem to parse the child properly, so the HTML just gets pasted into the Go code.

@a-h
Copy link
Owner

a-h commented May 10, 2023

Ah, you're right, I forgot to allow package names.

@a-h
Copy link
Owner

a-h commented Jun 20, 2023

I'm fairly sure this is solved in the referenced commit (2nd one) and the changes released in the latest releases of templ, if not please do re-open!

@a-h a-h closed this as completed Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants