diff options
Diffstat (limited to 'packages/integrations/mdx/src/utils.ts')
-rw-r--r-- | packages/integrations/mdx/src/utils.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/integrations/mdx/src/utils.ts b/packages/integrations/mdx/src/utils.ts index 766fef5ae..a76186292 100644 --- a/packages/integrations/mdx/src/utils.ts +++ b/packages/integrations/mdx/src/utils.ts @@ -1,7 +1,9 @@ import type { Options as AcornOpts } from 'acorn'; import { parse } from 'acorn'; import type { AstroConfig, SSRError } from 'astro'; +import { bold, yellow } from 'kleur/colors'; import matter from 'gray-matter'; +import type { PluggableList } from '@mdx-js/mdx/lib/core.js'; import type { MdxjsEsm } from 'mdast-util-mdx'; function appendForwardSlash(path: string) { @@ -82,3 +84,25 @@ export function jsToTreeNode( }, }; } + +export function ignoreStringPlugins(plugins: any[]): PluggableList { + let validPlugins: PluggableList = []; + let hasInvalidPlugin = false; + for (const plugin of plugins) { + if (typeof plugin === 'string') { + console.warn(yellow(`[MDX] ${bold(plugin)} not applied.`)); + hasInvalidPlugin = true; + } else if (Array.isArray(plugin) && typeof plugin[0] === 'string') { + console.warn(yellow(`[MDX] ${bold(plugin[0])} not applied.`)); + hasInvalidPlugin = true; + } else { + validPlugins.push(plugin); + } + } + if (hasInvalidPlugin) { + console.warn( + `To inherit Markdown plugins in MDX, please use explicit imports in your config instead of "strings." See Markdown docs: https://docs.astro.build/en/guides/markdown-content/#markdown-plugins` + ); + } + return validPlugins; +} |