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

Links within template Elements cause wrong HTML parsing/output #971

Open
1 task
diesieben07 opened this issue Feb 21, 2024 · 2 comments
Open
1 task

Links within template Elements cause wrong HTML parsing/output #971

diesieben07 opened this issue Feb 21, 2024 · 2 comments
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@diesieben07
Copy link

Astro Info

Astro                    v4.4.1
Node                     v20.11.1
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

n/a

Describe the Bug

Astro fails to parse a elements within template elements correctly in certain situations.
If the content of the a element is an expression, Astro emits the a element again after the template element.
The following is not handled correctly:

<template>
    <a href="https://example.com">{text}</a>.
</template>
<p>Some text</p>

The emitted HTML is equivalent to the following:

<template>
    <a href="https://example.com">Text</a>.
</template>
<a href="https://example.com">
<p>Some text</p>
</a>

This problem does not occur if the a Element only contains plain text (i.e. not an expression).

What's the expected result?

Astro should parse/emit a elements within template elements correctly.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-5amjgj?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Feb 21, 2024
@Princesseuh Princesseuh transferred this issue from withastro/astro Feb 21, 2024
@Princesseuh Princesseuh added - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs triage Issue needs to be triaged labels Feb 21, 2024
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Feb 21, 2024
@diesieben07
Copy link
Author

diesieben07 commented Feb 21, 2024

@Princesseuh I saw that you moved this issue to the compiler project. I threw together a quick test with @astrojs/compiler and it seems it generates the correct AST. I have shared the code here.
So the issue might be elsewhere.

Edit: The transformed output of the compiler (transform) has the issue. So the issue is with printing, not parsing.

@MoustaphaDev
Copy link
Member

Thanks for investigating @diesieben07!
This looks similars to #958, I'll make sure to look at this when I go through the issues next week.

@Princesseuh Princesseuh removed the needs triage Issue needs to be triaged label Mar 5, 2024
MoustaphaDev added a commit that referenced this issue Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

3 participants