summaryrefslogtreecommitdiff
path: root/packages/markdown
diff options
context:
space:
mode:
Diffstat (limited to 'packages/markdown')
-rw-r--r--packages/markdown/component/package.json7
-rw-r--r--packages/markdown/component/test/astro-markdown.test.js2
-rw-r--r--packages/markdown/component/test/fixtures/astro-markdown-plugins/package.json3
-rw-r--r--packages/markdown/component/test/fixtures/astro-markdown/package.json6
-rw-r--r--packages/markdown/remark/package.json2
-rw-r--r--packages/markdown/remark/src/load-plugins.ts15
6 files changed, 30 insertions, 5 deletions
diff --git a/packages/markdown/component/package.json b/packages/markdown/component/package.json
index b7878d027..8ba0b78b9 100644
--- a/packages/markdown/component/package.json
+++ b/packages/markdown/component/package.json
@@ -21,11 +21,16 @@
"test": "mocha --exit --timeout 20000"
},
"devDependencies": {
+ "@types/mocha": "^9.1.1",
"astro": "workspace:*",
"chai": "^4.3.6",
"cheerio": "^1.0.0-rc.11",
+ "github-slugger": "^1.4.0",
"mocha": "^9.2.2",
- "@types/mocha": "^9.1.1"
+ "rehype-autolink-headings": "^6.1.1",
+ "rehype-slug": "^5.0.1",
+ "rehype-toc": "^3.0.2",
+ "remark-code-titles": "^0.1.2"
},
"keywords": [
"astro",
diff --git a/packages/markdown/component/test/astro-markdown.test.js b/packages/markdown/component/test/astro-markdown.test.js
index c0726d2ca..e5a1382a5 100644
--- a/packages/markdown/component/test/astro-markdown.test.js
+++ b/packages/markdown/component/test/astro-markdown.test.js
@@ -12,6 +12,8 @@ describe('Astro Markdown', () => {
await fixture.build();
});
+ // NOTE: This test uses legacy markdown, which requires `github-slugger` to be installed.
+ // This breaks in strict dependency installation, but since it's a legacy feature, ignore for now.
it('Can load markdown pages with Astro', async () => {
const html = await fixture.readFile('/post/index.html');
const $ = cheerio.load(html);
diff --git a/packages/markdown/component/test/fixtures/astro-markdown-plugins/package.json b/packages/markdown/component/test/fixtures/astro-markdown-plugins/package.json
index 4babf437a..77481c297 100644
--- a/packages/markdown/component/test/fixtures/astro-markdown-plugins/package.json
+++ b/packages/markdown/component/test/fixtures/astro-markdown-plugins/package.json
@@ -3,10 +3,11 @@
"version": "0.0.0",
"private": true,
"dependencies": {
- "@astrojs/preact": "workspace:*",
"@astrojs/markdown-component": "workspace:*",
+ "@astrojs/preact": "workspace:*",
"astro": "workspace:*",
"hast-util-select": "^5.0.2",
+ "preact": "^10.11.0",
"rehype-slug": "^5.0.1"
}
}
diff --git a/packages/markdown/component/test/fixtures/astro-markdown/package.json b/packages/markdown/component/test/fixtures/astro-markdown/package.json
index a5864786e..8dec19e14 100644
--- a/packages/markdown/component/test/fixtures/astro-markdown/package.json
+++ b/packages/markdown/component/test/fixtures/astro-markdown/package.json
@@ -3,9 +3,11 @@
"version": "0.0.0",
"private": true,
"dependencies": {
+ "@astrojs/markdown-component": "workspace:*",
"@astrojs/preact": "workspace:*",
"@astrojs/svelte": "workspace:*",
- "@astrojs/markdown-component": "workspace:*",
- "astro": "workspace:*"
+ "astro": "workspace:*",
+ "preact": "^10.11.0",
+ "svelte": "^3.48.0"
}
}
diff --git a/packages/markdown/remark/package.json b/packages/markdown/remark/package.json
index 6178bf014..36b702d93 100644
--- a/packages/markdown/remark/package.json
+++ b/packages/markdown/remark/package.json
@@ -30,6 +30,8 @@
"acorn-jsx": "^5.3.2",
"github-slugger": "^1.4.0",
"hast-util-to-html": "^8.0.3",
+ "import-meta-resolve": "^2.1.0",
+ "mdast-util-from-markdown": "^1.2.0",
"mdast-util-mdx-expression": "^1.2.1",
"mdast-util-mdx-jsx": "^1.2.0",
"micromark-extension-mdx-expression": "^1.0.3",
diff --git a/packages/markdown/remark/src/load-plugins.ts b/packages/markdown/remark/src/load-plugins.ts
index c64d13543..37798db14 100644
--- a/packages/markdown/remark/src/load-plugins.ts
+++ b/packages/markdown/remark/src/load-plugins.ts
@@ -1,8 +1,21 @@
+import path from 'path';
+import { pathToFileURL } from 'url';
import * as unified from 'unified';
+import { resolve as importMetaResolve } from 'import-meta-resolve';
+
+const cwdUrlStr = pathToFileURL(path.join(process.cwd(), 'package.json')).toString();
async function importPlugin(p: string | unified.Plugin): Promise<unified.Plugin> {
if (typeof p === 'string') {
- const importResult = await import(p);
+ // Try import from this package first
+ try {
+ const importResult = await import(p);
+ return importResult.default;
+ } catch {}
+
+ // Try import from user project
+ const resolved = await importMetaResolve(p, cwdUrlStr);
+ const importResult = await import(resolved);
return importResult.default;
}