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

Function embed

src/language-html/embed.js:36–159  ·  view source on GitHub ↗
(path, options)

Source from the content-addressed store, hash-verified

34]);
35
36function embed(path, options) {
37 const { node } = path;
38
39 switch (node.kind) {
40 case "element":
41 if (isScriptLikeTag(node, options) || node.kind === "interpolation") {
42 // Fall through to "text"
43 return;
44 }
45
46 if (!node.isSelfClosing && isVueNonHtmlBlock(node, options)) {
47 const parser = inferElementParser(node, options);
48 if (!parser) {
49 return;
50 }
51
52 return async (textToDoc, print) => {
53 const content = getNodeContent(node, options);
54 let isEmpty = /^\s*$/.test(content);
55 let doc = "";
56 if (!isEmpty) {
57 doc = await textToDoc(htmlTrimPreserveIndentation(content), {
58 parser,
59 __embeddedInHtml: true,
60 });
61 isEmpty = doc === "";
62 }
63
64 return [
65 printOpeningTagPrefix(node, options),
66 group(printOpeningTag(path, options, print)),
67 isEmpty ? "" : hardline,
68 doc,
69 isEmpty ? "" : hardline,
70 printClosingTag(node, options),
71 printClosingTagSuffix(node, options),
72 ];
73 };
74 }
75 break;
76
77 case "text":
78 if (isScriptLikeTag(node.parent, options)) {
79 const parser = inferElementParser(node.parent, options);
80 if (parser) {
81 return async (textToDoc) => {
82 const value =
83 parser === "markdown"
84 ? htmlWhitespace.dedentString(
85 node.value.replace(/^[^\S\n]*\n/, ""),
86 )
87 : node.value;
88 const textToDocOptions = { parser, __embeddedInHtml: true };
89 if (options.parser === "html" && parser === "babel") {
90 let sourceType = "script";
91 const { attrMap } = node.parent;
92 if (
93 attrMap &&

Callers

nothing calls this directly

Calls 15

isScriptLikeTagFunction · 0.90
isVueNonHtmlBlockFunction · 0.90
inferElementParserFunction · 0.90
printOpeningTagPrefixFunction · 0.90
groupFunction · 0.90
printOpeningTagFunction · 0.90
printClosingTagFunction · 0.90
printClosingTagSuffixFunction · 0.90
indentFunction · 0.90
formatAttributeValueFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…