dprint-plugin-typescript icon indicating copy to clipboard operation
dprint-plugin-typescript copied to clipboard

Format html tagged template text

Open dsherret opened this issue 5 years ago • 4 comments

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...

dsherret avatar Apr 04 '20 23:04 dsherret

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.

zandaqo avatar Jul 05 '22 07:07 zandaqo