Skip to content

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

Merged
dsherret merged 28 commits into
dprint:mainfrom
kt3k:html_css_templates_2
Apr 25, 2025
Merged

feat: support formatting of languages embedded in tagged template literals (Rust API Only)#701
dsherret merged 28 commits into
dprint:mainfrom
kt3k:html_css_templates_2

Conversation

@kt3k

@kt3k kt3k commented Feb 27, 2025

Copy link
Copy Markdown
Contributor

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

CLAassistant commented Feb 27, 2025

Copy link
Copy Markdown

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

kt3k commented Mar 7, 2025

Copy link
Copy Markdown
Contributor Author

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

@bartlomieju

Copy link
Copy Markdown
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

kt3k commented Apr 23, 2025

Copy link
Copy Markdown
Contributor Author

Sure!

@kt3k

kt3k commented Apr 24, 2025

Copy link
Copy Markdown
Contributor Author

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

@dsherret dsherret left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown

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!

@xseman

xseman commented Jan 25, 2026

Copy link
Copy Markdown

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!

I'm encountering the same issue. Was this resolved? If there's a specific configuration needed to fix this, please let me know.

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.

7 participants