From eafbf1b1de4a948429f0c3f891d13073f2c48fe4 Mon Sep 17 00:00:00 2001 From: Ze-Zheng Wu Date: Sat, 24 Feb 2024 18:17:07 +0800 Subject: [PATCH] fix(`css`): embedded `css` formatting behavior Make embedded `css` formatting more align with the built-in behavior. --- .changeset/silver-rings-dress.md | 5 +++++ src/embedded/css/embedder.ts | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .changeset/silver-rings-dress.md diff --git a/.changeset/silver-rings-dress.md b/.changeset/silver-rings-dress.md new file mode 100644 index 0000000..a54927b --- /dev/null +++ b/.changeset/silver-rings-dress.md @@ -0,0 +1,5 @@ +--- +"prettier-plugin-embed": patch +--- + +Make embedded `css` formatting more align with the built-in behavior. diff --git a/src/embedded/css/embedder.ts b/src/embedded/css/embedder.ts index 1ebeedd..70e585d 100644 --- a/src/embedded/css/embedder.ts +++ b/src/embedded/css/embedder.ts @@ -24,7 +24,10 @@ export const embedder: Embedder = async ( const { node } = path; - const { createPlaceholder, placeholderRegex } = preparePlaceholder("@p"); + // https://github.com/prettier/prettier/blob/3bfabd012873e5022f341aca75566966d91870f1/src/language-css/utils/index.js#L206-L208 + const { createPlaceholder, placeholderRegex } = preparePlaceholder( + "@prettier-placeholder", + ); const text = node.quasis .map((quasi, index, { length }) => @@ -49,7 +52,13 @@ export const embedder: Embedder = async ( parser: resolvedOptions.embeddedCssParser ?? "scss", }); - const contentDoc = simpleRehydrateDoc(doc, placeholderRegex, expressionDocs); + const contentDoc = simpleRehydrateDoc( + doc, + placeholderRegex, + expressionDocs, + // https://github.com/prettier/prettier/blob/3bfabd012873e5022f341aca75566966d91870f1/src/language-js/embed/css.js#L52 + true, + ); if ( resolvedOptions.preserveEmbeddedExteriorWhitespaces?.includes(commentOrTag)