MCPcopy
hub / github.com/prettier/prettier / embed

Function embed

src/language-handlebars/embed.js:1–41  ·  view source on GitHub ↗
(path /* , options*/)

Source from the content-addressed store, hash-verified

1function embed(path /* , options*/) {
2 const { node } = path;
3
4 if (node.type !== "TextNode") {
5 return;
6 }
7
8 const { parent } = path;
9
10 if (!(
11 parent.type === "ElementNode" &&
12 parent.tag === "style" &&
13 parent.children.length === 1 &&
14 parent.children[0] === node
15 )) {
16 return;
17 }
18
19 const languageAttribute = parent.attributes.find(
20 (attribute) => attribute.type === "AttrNode" && attribute.name === "lang",
21 );
22 if (
23 languageAttribute &&
24 !(
25 languageAttribute.value.type === "TextNode" &&
26 (languageAttribute.value.chars === "" ||
27 languageAttribute.value.chars === "css")
28 )
29 ) {
30 return;
31 }
32
33 return async (textToDoc) => {
34 const context = node.chars;
35 if (!context.trim()) {
36 return "";
37 }
38 const doc = await textToDoc(context, { parser: "css" });
39 return doc;
40 };
41}
42
43export default embed;

Callers

nothing calls this directly

Calls 2

textToDocFunction · 0.85
trimMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…