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

Astros Code component ignores class:list attribute #9009

Closed
1 task done
vinnichase opened this issue Nov 6, 2023 · 5 comments · Fixed by #9960
Closed
1 task done

Astros Code component ignores class:list attribute #9009

vinnichase opened this issue Nov 6, 2023 · 5 comments · Fixed by #9960
Labels
- P2: nice to have Not breaking anything but nice to have (priority)

Comments

@vinnichase
Copy link

Astro Info

Astro                    v3.4.3
Node                     v18.17.0
System                   macOS (arm64)
Package Manager          unknown
Output                   server
Adapter                  astro-sst
Integrations             @astrojs/tailwind

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

Chrome

Describe the Bug

Astros Code component doesn't add classes from class:list attribute:

---
import { Code } from 'astro:components';
---

<html lang="en">
	<head>
		<meta charset="utf-8" />
		<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
		<meta name="viewport" content="width=device-width" />
		<meta name="generator" content={Astro.generator} />
		<title>Astro</title>
	</head>
	<body>
		<h1>Astro</h1>
		<Code code="{}" lang="json" class:list={['test']} />
	</body>
</html>

Renders this output without the test class in the pre or the code element:

<pre
      class="astro-code github-dark"
      style="background-color: #24292e; color: #e1e4e8; overflow-x: auto"
      tabindex="0"
      lang="json"
    ><code><span class="line"><span style="color:#E1E4E8">{}</span></span></code></pre>

What's the expected result?

<pre
      class="astro-code github-dark test"
      style="background-color: #24292e; color: #e1e4e8; overflow-x: auto"
      tabindex="0"
      lang="json"
    ><code><span class="line"><span style="color:#E1E4E8">{}</span></span></code></pre>

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-fvzhsf?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 Nov 6, 2023
@bluwy
Copy link
Member

bluwy commented Nov 13, 2023

It's not just class:list, the <Code /> component doesn't accept any other attributes other than the documented ones. It would be nice to have though.

@bluwy bluwy added - P2: nice to have Not breaking anything but nice to have (priority) and removed needs triage Issue needs to be triaged labels Nov 13, 2023
@florian-lefebvre
Copy link
Member

Is it possible though? It renders a Fragment so is it possible to forward props?

@bluwy
Copy link
Member

bluwy commented Nov 24, 2023

I was thinking we can inject the classes into the raw html string. Either through regex, or through the hast at

@florian-lefebvre
Copy link
Member

I was thinking about forwarding any props (with the HTMLAttributes type). Do you think it makes too complicated with regexes?

@bluwy
Copy link
Member

bluwy commented Jan 1, 2024

If we want to forward any props, I think using the hast would be safest. Regexes are only for the fields we know exists after shiki renders the HTML.

@matthewp matthewp added good first issue Good for newcomers. If you need additional guidance, feel free to post in #dev on Discord and removed good first issue Good for newcomers. If you need additional guidance, feel free to post in #dev on Discord labels Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants