Skip to content

feat: support formatting of languages embedded in tagged template literals (Rust API Only) #701

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

Merged
merged 28 commits into from
Apr 25, 2025

Conversation

kt3k
Copy link
Contributor

@kt3k kt3k commented Feb 27, 2025

continued from #683
towards denoland/deno#26880

Updates from the above:

  • Supports css, styled.foo, and styled(Foo) tags for css, html tag for html, sql tag for sql.
  • Supports the case of multiple quasis
    • using dprint_placeholder_N_id for the placeholders between quasis (The identifier is inspired by prettier implementation css html)
  • Uses malva (css), markup_fmt (html), and dprint-plugin-sql (sql) for testing.
    • Note: The above form of placeholder seems working with these formatters.

(Didn't add support of styled-jsx (<style jsx>) as it seems less popular these days).


remaining tasks:


references:

@CLAassistant
Copy link

CLAassistant commented Feb 27, 2025

CLA assistant check
All committers have signed the CLA.

@kt3k kt3k force-pushed the html_css_templates_2 branch from cf05f55 to b527e1f Compare March 5, 2025 09:22
@kt3k
Copy link
Contributor Author

kt3k commented Mar 7, 2025

@dsherret I think now this is ready for review. PTAL when you have time

@bartlomieju
Copy link
Collaborator

@kt3k can you please open a PR to Deno with a Cargo patch pointing to this PR to test it end-to-end?

@kt3k
Copy link
Contributor Author

kt3k commented Apr 23, 2025

Sure!

@kt3k
Copy link
Contributor Author

kt3k commented Apr 24, 2025

Opened denoland/deno#29014

@dsherret dsherret changed the title feat: support formatting of languages embedded in tagged template literals feat: support formatting of languages embedded in tagged template literals (Rust API Only) Apr 25, 2025
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Note to others: this is currently just for the Rust API. Support for Wasm will come later.

@dsherret dsherret merged commit b3abdf2 into dprint:main Apr 25, 2025
3 checks passed
@kt3k kt3k deleted the html_css_templates_2 branch April 26, 2025 12:38
kt3k added a commit to denoland/deno that referenced this pull request Apr 29, 2025
This commit adds the formatting of CSS, HTML, and SQL which are embedded in
Tagged Template Literal strings. The embedded languages are detected by
the tag name of the literal.

```ts
// triggers CSS formatting
const Div = styled.div`
  margin: 5px;
  padding: ${padding}px;
`;

// triggers HTML formatting
document.body.innerHTML = html`
  <main>
    <h1>Hello ${name}!<h1>
  </main>
`;

// triggers SQL formatting when `--unstable-sql` passed
const query = sql`
  SELECT
    ${table}.${field}
  FROM
    ${table};
`
```

See dprint/dprint-plugin-typescript#701 for more
details
@adrian-gierakowski
Copy link

Supports css, styled.foo, and styled(Foo) tags for css

does it mean this can be closed as resolved now?

if so, do I need to configure anything to start using it? Thanks!

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

Successfully merging this pull request may close these issues.

5 participants