npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tagged-jsx/prettier-plugin

v1.0.2

Published

A prettier plugin for formatting tagged template JSX

Readme

@tagged-jsx/prettier-plugin

A Prettier plugin for formatting JSX content inside tagged template literals. Supports both Node.js and browser (Web) environments.

// Before:
const el = html`<div
class=${cls}><span>hello</span></div>`

// After:
const el = html`<div class=${cls}>
  <span>hello</span>
</div>`

Installation

npm install --save-dev @tagged-jsx/prettier-plugin

Requires prettier as a peer dependency (^3.0.0).

Usage

Prettier config (recommended)

{
  "plugins": ["@tagged-jsx/prettier-plugin"],
  "embeddedJsxTags": ["jsx", "html"]
}

Then format normally:

npx prettier --write src/

Programmatic API

import { createPlugin } from "@tagged-jsx/prettier-plugin";
import prettier from "prettier";

const plugin = createPlugin(["jsx", "html"]);

const result = await prettier.format(source, {
  parser: "typescript",
  plugins: [plugin],
});

Web / browser

For browser environments where prettier/parser-typescript and prettier/parser-babel are loaded separately:

import { createPlugin } from "@tagged-jsx/prettier-plugin/web";
import prettier from "prettier/standalone";
import tsParser from "prettier/plugins/typescript";
import babelParser from "prettier/plugins/babel";

const plugin = createPlugin(["jsx", "html"]);

const result = await prettier.format(source, {
  parser: "typescript",
  plugins: [plugin, tsParser, babelParser],
});

How it works

The plugin registers a custom Prettier printer that extends the estree AST format printer (via prettier-plugin-embed). When formatting, it:

  1. Walks the TypeScript/Babel AST looking for TaggedTemplateExpression nodes
  2. Checks the tag name against the configured tags (e.g., jsx, html)
  3. Extracts the template strings from the TemplateLiteral quasi
  4. Tokenizes the strings using @tagged-jsx/parse's tokenize() function
  5. Parses the tokens into an AST using parse()
  6. Prints the AST back using Prettier's document builders (group, indent, softline, hardline, ifBreak)
  7. Embeds the formatted result inside the original template literal, replacing the content

Print logic

The plugin's printJsx function handles each node type:

Elements: Tag names are printed as-is (or as expressions for dynamic components via ${Component}). Attributes are grouped and indented:

<tagName
  attr1="value1"
  attr2=${expression}
  ...${spread}
/>

Children: Text nodes are trimmed of excess whitespace. Elements on adjacent lines get hardline separators. Expression children (${...}) are preserved with their inner formatting delegated to the parent printer.

Fragments: Multiple root-level children are handled gracefully, with each child separated by line breaks.

Line comments on attributes: Line comments (// comment) appearing inline after an attribute are preserved on the same line. Comments on their own line remain on their own line.

Self-closing elements: Elements with no children or with explicit self-closing tokens render as <tagName /> (with a space before />).

Expression handling

The plugin delegates expression formatting to Prettier's built-in estree printer via the embed API. This means ${someFunction(a, b)} is formatted by Prettier's standard JavaScript printer, not by this plugin. The plugin only handles the JSX structural formatting around expressions.

Formatting rules

Inlined elements (single child, no nested elements, few attributes):

html`<div>${content}</div>`

Broken elements (multiple children, nested elements, 2+ attributes):

html`<div class=${cls} id=${id}>
  <span>hello</span>
  ${content}
</div>`

SolidJS control flow:

html`<${Show} when=${() => visible}>
  <p>${() => text}</p>
</${Show}>`

SolidJS list rendering:

html`<ul>
  <${For} each=${() => items}>
    ${(item) => html`<li>${item}</li>`}
  </${For}>
</ul>`

Self-closing:

html`<input type="text" disabled />`

Dynamic tags:

html`<${Component} prop=${value}>
  ${children}
</${Component}>`

License

MIT