Skip to content

Commit

Permalink
fix(css): embedded css formatting behavior
Browse files Browse the repository at this point in the history
Make embedded `css` formatting more align with the built-in behavior.
  • Loading branch information
Sec-ant committed Feb 27, 2024
1 parent e66c5fd commit eafbf1b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-rings-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"prettier-plugin-embed": patch
---

Make embedded `css` formatting more align with the built-in behavior.
13 changes: 11 additions & 2 deletions src/embedded/css/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export const embedder: Embedder<Options> = 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 }) =>
Expand All @@ -49,7 +52,13 @@ export const embedder: Embedder<Options> = 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)
Expand Down

0 comments on commit eafbf1b

Please sign in to comment.