Skip to content

Format html tagged template text #9

Closed

Description

@dsherret

It would be nice to format html in tagged templates as Prettier does.

For example:

const t = html `
                <tr>
                  <td class="mode">
                    ${entry.mode}
                  </td>
                  <td>
                    ${entry.size}
                  </td>
                  <td>
                    <a href="${entry.url}">${entry.name}</a>
                  </td>
                </tr>
              `;

Should format as:

const t = html`
  <tr>
    <td class="mode">
      ${entry.mode}
    </td>
    <td>
      ${entry.size}
    </td>
    <td>
      <a href="${entry.url}">${entry.name}</a>
    </td>
  </tr>
`;

This will probably be a bit of work though...

Activity

  1. transferred this issue fromdprint/dprinton Jun 6, 2020
  2. added
    enhancement
    on Jun 6, 2020
  3. zandaqo commented on Jul 5, 2022

    @zandaqo

    From HN:

    It's definitely something I would like to implement. I haven't found a parser that would be good for formatting yet so maybe I will have to write my own :/

    Could sax-wasm be a good fit here? It's an HTML parser written in Rust, and I believe I've seen a few folks in Lit community using it with their tagged templates.

  4. mohamedmansour commented on Dec 15, 2024

    @mohamedmansour
  5. warpfork commented on Aug 16, 2025

    @warpfork

    Crosslinking for anyone else who may be currently finding this issue:

    There's been huge strides on this lately in #701 !

  6. warpfork commented on Aug 21, 2025

    @warpfork

    So (IIUC) after 701, there's most of the code written. It's mostly the wiring and the config and the shipping of wasm that's still to be settled, per

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

    Originally posted by @dsherret in #701 (review)

    Also, the diff in https://github.com/denoland/deno/pull/29014/files is lovely for fully demonstrating what's still needed to put that work into use (when one is willing/able to use the Rust API directly, instead of the CLI+plugins).

    In what's left: Is the path forward on this well mapped out?

    I started to take a look at it myself, but ended up with a lot of questions. Mainly around dependencies and configuration:

    • is it okay to lock in the malva and markup_fmt plugins as dependencies of this crate? (they already are... in test. I'm not sure how to avoid making them full (if feature-flagged?) dependencies. I'm not sure feature-flagging combined with the wasm distribution pipeline really makes a ton of sense.)
    • should the configuration try to look at the top level config for malva and markup and use that for the nested sections?
      • (is this currently even possible through the dprint API for config...?)
    • or should it support a nested config block within the typescript config, and so they could diverge?
    • or stack them? use the top level config as a default, and allow overriding?

    I could consider taking a crack at this, if it's helpful? Really eager to have these powers become available :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions