summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/astro/package.json2
-rw-r--r--packages/astro/src/@types/astro.ts16
-rw-r--r--packages/astro/test/astro-markdown-plugins.test.js7
-rw-r--r--packages/markdown/remark/CHANGELOG.md2
-rw-r--r--packages/markdown/remark/package.json27
-rw-r--r--packages/markdown/remark/src/index.ts18
6 files changed, 40 insertions, 32 deletions
diff --git a/packages/astro/package.json b/packages/astro/package.json
index 06176c8ca..a88a30210 100644
--- a/packages/astro/package.json
+++ b/packages/astro/package.json
@@ -87,7 +87,7 @@
"path-to-regexp": "^6.2.0",
"postcss": "^8.3.8",
"prismjs": "^1.25.0",
- "remark-slug": "^7.0.0",
+ "rehype-slug": "^5.0.0",
"resolve": "^1.20.0",
"rollup": "^2.57.0",
"sass": "^1.43.3",
diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts
index cc2aa7b9d..bce09f050 100644
--- a/packages/astro/src/@types/astro.ts
+++ b/packages/astro/src/@types/astro.ts
@@ -90,7 +90,7 @@ export interface AstroUserConfig {
renderers?: string[];
/** Options for rendering markdown content */
markdownOptions?: {
- render?: [string, Record<string, any>];
+ render?: [string | MarkdownParser, Record<string, any>];
};
/** Options specific to `astro build` */
buildOptions?: {
@@ -196,6 +196,20 @@ export interface ManifestData {
routes: RouteData[];
}
+export type MarkdownParser = (contents: string, options?: Record<string, any>) => MarkdownParserResponse | PromiseLike<MarkdownParserResponse>;
+
+export interface MarkdownParserResponse {
+ frontmatter: {
+ [key: string]: any;
+ };
+ metadata: {
+ headers: any[];
+ source: string;
+ html: string;
+ };
+ code: string;
+}
+
/**
* paginate() Options
* Docs: https://docs.astro.build/guides/pagination/#calling-the-paginate-function
diff --git a/packages/astro/test/astro-markdown-plugins.test.js b/packages/astro/test/astro-markdown-plugins.test.js
index 4aed4c295..eab3f35a6 100644
--- a/packages/astro/test/astro-markdown-plugins.test.js
+++ b/packages/astro/test/astro-markdown-plugins.test.js
@@ -14,11 +14,8 @@ describe('Astro Markdown plugins', () => {
render: [
markdownRemark,
{
- remarkPlugins: ['remark-code-titles', 'remark-slug', ['rehype-autolink-headings', { behavior: 'prepend' }]],
- rehypePlugins: [
- ['rehype-toc', { headings: ['h2', 'h3'] }],
- ['rehype-add-classes', { 'h1,h2,h3': 'title' }],
- ],
+ remarkPlugins: ['remark-code-titles', ['rehype-autolink-headings', { behavior: 'prepend' }]],
+ rehypePlugins: [['rehype-toc', { headings: ['h2', 'h3'] }], ['rehype-add-classes', { 'h1,h2,h3': 'title' }], 'rehype-slug'],
},
],
},
diff --git a/packages/markdown/remark/CHANGELOG.md b/packages/markdown/remark/CHANGELOG.md
index 701e045ab..d92ce6782 100644
--- a/packages/markdown/remark/CHANGELOG.md
+++ b/packages/markdown/remark/CHANGELOG.md
@@ -1,4 +1,4 @@
-# @astrojs/markdown-support
+# @astrojs/markdown-remark
## 0.4.0
diff --git a/packages/markdown/remark/package.json b/packages/markdown/remark/package.json
index 22522bea3..384537881 100644
--- a/packages/markdown/remark/package.json
+++ b/packages/markdown/remark/package.json
@@ -19,25 +19,24 @@
},
"dependencies": {
"@astrojs/prism": "^0.3.0",
- "@silvenon/remark-smartypants": "^1.0.0",
"assert": "^2.0.0",
- "github-slugger": "^1.3.0",
+ "github-slugger": "^1.4.0",
"gray-matter": "^4.0.3",
"mdast-util-mdx-expression": "^1.1.1",
- "mdast-util-mdx-jsx": "^1.1.1",
- "micromark-extension-mdx-expression": "^1.0.0",
- "micromark-extension-mdx-jsx": "^1.0.0",
+ "mdast-util-mdx-jsx": "^1.1.3",
+ "micromark-extension-mdx-expression": "^1.0.3",
+ "micromark-extension-mdx-jsx": "^1.0.2",
"prismjs": "^1.25.0",
- "rehype-raw": "^6.0.0",
- "rehype-stringify": "^9.0.1",
- "remark-footnotes": "^4.0.1",
- "remark-gfm": "^2.0.0",
- "remark-parse": "^10.0.0",
- "remark-rehype": "^9.0.0",
- "remark-slug": "^7.0.0",
- "unified": "^10.1.0",
+ "rehype-raw": "^6.1.0",
+ "rehype-slug": "^5.0.0",
+ "rehype-stringify": "^9.0.2",
+ "remark-gfm": "^3.0.1",
+ "remark-parse": "^10.0.1",
+ "remark-rehype": "^10.0.1",
+ "remark-smartypants": "^2.0.0",
+ "unified": "^10.1.1",
"unist-util-map": "^3.0.0",
- "unist-util-visit": "^4.0.0"
+ "unist-util-visit": "^4.1.0"
},
"devDependencies": {
"@types/github-slugger": "^1.3.0",
diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts
index 8ea5263b8..88033db14 100644
--- a/packages/markdown/remark/src/index.ts
+++ b/packages/markdown/remark/src/index.ts
@@ -28,20 +28,13 @@ export async function renderMarkdownWithFrontmatter(contents: string, opts?: Mar
return { ...value, frontmatter };
}
-export const DEFAULT_REMARK_PLUGINS = [
- 'remark-gfm',
- 'remark-footnotes',
- // TODO: reenable smartypants!
- // '@silvenon/remark-smartypants'
-];
+export const DEFAULT_REMARK_PLUGINS = ['remark-gfm', 'remark-smartypants'];
-export const DEFAULT_REHYPE_PLUGINS = [
- // empty
-];
+export const DEFAULT_REHYPE_PLUGINS = ['rehype-slug'];
/** Shared utility for rendering markdown */
export async function renderMarkdown(content: string, opts?: MarkdownRenderingOptions | null) {
- const { remarkPlugins = DEFAULT_REMARK_PLUGINS, rehypePlugins = DEFAULT_REHYPE_PLUGINS } = opts ?? {};
+ let { remarkPlugins = [], rehypePlugins = [] } = opts ?? {};
const scopedClassName = opts?.$?.scopedClassName;
const mode = opts?.mode ?? 'mdx';
const isMDX = mode === 'mdx';
@@ -55,6 +48,11 @@ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOp
.use(isMDX ? [remarkExpressions] : [])
.use([remarkUnwrap]);
+ if (remarkPlugins.length === 0 && rehypePlugins.length === 0) {
+ remarkPlugins = [...DEFAULT_REMARK_PLUGINS];
+ rehypePlugins = [...DEFAULT_REHYPE_PLUGINS];
+ }
+
const loadedRemarkPlugins = await Promise.all(loadPlugins(remarkPlugins));
const loadedRehypePlugins = await Promise.all(loadPlugins(rehypePlugins));