diff options
Diffstat (limited to 'packages/integrations/mdx/src')
-rw-r--r-- | packages/integrations/mdx/src/plugins.ts | 36 | ||||
-rw-r--r-- | packages/integrations/mdx/src/utils.ts | 18 |
2 files changed, 1 insertions, 53 deletions
diff --git a/packages/integrations/mdx/src/plugins.ts b/packages/integrations/mdx/src/plugins.ts index cf30566c4..7d475a7f3 100644 --- a/packages/integrations/mdx/src/plugins.ts +++ b/packages/integrations/mdx/src/plugins.ts @@ -10,19 +10,16 @@ import type { AstroConfig } from 'astro'; import type { Literal, MemberExpression } from 'estree'; import { visit as estreeVisit } from 'estree-util-visit'; import { bold, yellow } from 'kleur/colors'; -import type { Image } from 'mdast'; -import { pathToFileURL } from 'node:url'; import rehypeRaw from 'rehype-raw'; import remarkGfm from 'remark-gfm'; import remarkSmartypants from 'remark-smartypants'; -import { visit } from 'unist-util-visit'; import type { VFile } from 'vfile'; import { MdxOptions } from './index.js'; import { rehypeInjectHeadingsExport } from './rehype-collect-headings.js'; import rehypeMetaString from './rehype-meta-string.js'; import remarkPrism from './remark-prism.js'; import remarkShiki from './remark-shiki.js'; -import { isRelativePath, jsToTreeNode } from './utils.js'; +import { jsToTreeNode } from './utils.js'; export function recmaInjectImportMetaEnvPlugin({ importMetaEnv, @@ -96,34 +93,6 @@ export function rehypeApplyFrontmatterExport() { }; } -/** - * `src/content/` does not support relative image paths. - * This plugin throws an error if any are found - */ -function toRemarkContentRelImageError({ srcDir }: { srcDir: URL }) { - const contentDir = new URL('content/', srcDir); - return function remarkContentRelImageError() { - return (tree: any, vfile: VFile) => { - const isContentFile = pathToFileURL(vfile.path).href.startsWith(contentDir.href); - if (!isContentFile) return; - - const relImagePaths = new Set<string>(); - visit(tree, 'image', function raiseError(node: Image) { - if (isRelativePath(node.url)) { - relImagePaths.add(node.url); - } - }); - if (relImagePaths.size === 0) return; - - const errorMessage = - `Relative image paths are not supported in the content/ directory. Place local images in the public/ directory and use absolute paths (see https://docs.astro.build/en/guides/images/#in-markdown-files):\n` + - [...relImagePaths].map((path) => JSON.stringify(path)).join(',\n'); - - throw new Error(errorMessage); - }; - }; -} - export async function getRemarkPlugins( mdxOptions: MdxOptions, config: AstroConfig @@ -147,9 +116,6 @@ export async function getRemarkPlugins( remarkPlugins.push(remarkPrism); } - // Apply last in case user plugins resolve relative image paths - remarkPlugins.push(toRemarkContentRelImageError(config)); - return remarkPlugins; } diff --git a/packages/integrations/mdx/src/utils.ts b/packages/integrations/mdx/src/utils.ts index 516cfafb2..766fef5ae 100644 --- a/packages/integrations/mdx/src/utils.ts +++ b/packages/integrations/mdx/src/utils.ts @@ -82,21 +82,3 @@ export function jsToTreeNode( }, }; } - -// Following utils taken from `packages/astro/src/core/path.ts`: -export function isRelativePath(path: string) { - return startsWithDotDotSlash(path) || startsWithDotSlash(path); -} - -function startsWithDotDotSlash(path: string) { - const c1 = path[0]; - const c2 = path[1]; - const c3 = path[2]; - return c1 === '.' && c2 === '.' && c3 === '/'; -} - -function startsWithDotSlash(path: string) { - const c1 = path[0]; - const c2 = path[1]; - return c1 === '.' && c2 === '/'; -} |