(path, options)
| 4 | import { getFencedCodeBlockValue } from "./utilities.js"; |
| 5 | |
| 6 | function embed(path, options) { |
| 7 | const { node } = path; |
| 8 | |
| 9 | switch (node.type) { |
| 10 | case "code": { |
| 11 | const { lang: language } = node; |
| 12 | if (!language) { |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | let parser; |
| 17 | // https://shiki.style/references/engine-js-compat#supported-languages |
| 18 | if (language === "angular-ts") { |
| 19 | parser = inferParser(options, { language: "typescript" }); |
| 20 | } else if (language === "angular-html") { |
| 21 | parser = "angular"; |
| 22 | } else { |
| 23 | parser = inferParser(options, { language }); |
| 24 | } |
| 25 | |
| 26 | if (!parser) { |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | return async (textToDoc) => { |
| 31 | const textToDocOptions = { parser }; |
| 32 | |
| 33 | // Override the filepath option. |
| 34 | // This is because whether the trailing comma of type parameters |
| 35 | // should be printed depends on whether it is `*.ts` or `*.tsx`. |
| 36 | // https://github.com/prettier/prettier/issues/15282 |
| 37 | if (language === "ts" || language === "typescript") { |
| 38 | textToDocOptions.filepath = "dummy.ts"; |
| 39 | } else if (language === "tsx") { |
| 40 | textToDocOptions.filepath = "dummy.tsx"; |
| 41 | } |
| 42 | |
| 43 | const doc = await textToDoc( |
| 44 | options.parser === "mdx" |
| 45 | ? getFencedCodeBlockValue(node, options.originalText) |
| 46 | : node.value, |
| 47 | textToDocOptions, |
| 48 | ); |
| 49 | |
| 50 | const styleUnit = options.__inJsTemplate ? "~" : "`"; |
| 51 | const style = styleUnit.repeat( |
| 52 | Math.max(3, getMaxContinuousCount(node.value, styleUnit) + 1), |
| 53 | ); |
| 54 | |
| 55 | return markAsRoot([ |
| 56 | style, |
| 57 | node.lang, |
| 58 | node.meta ? " " + node.meta : "", |
| 59 | hardline, |
| 60 | replaceEndOfLine(doc), |
| 61 | hardline, |
| 62 | style, |
| 63 | ]); |
nothing calls this directly
no test coverage detected
searching dependent graphs…