@astrojs/markdown-remark 1.2.0 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- @astrojs/markdown-remark:build: cache hit, replaying output 968e841d80fa22fa
1
+ @astrojs/markdown-remark:build: cache hit, replaying output 34663a00ad52a28a
2
2
  @astrojs/markdown-remark:build: 
3
- @astrojs/markdown-remark:build: > @astrojs/markdown-remark@1.2.0 build /home/runner/work/astro/astro/packages/markdown/remark
3
+ @astrojs/markdown-remark:build: > @astrojs/markdown-remark@2.0.0-beta.0 build /home/runner/work/astro/astro/packages/markdown/remark
4
4
  @astrojs/markdown-remark:build: > astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json
5
5
  @astrojs/markdown-remark:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,105 @@
1
1
  # @astrojs/markdown-remark
2
2
 
3
+ ## 2.0.0-beta.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#5687](https://github.com/withastro/astro/pull/5687) [`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Give remark and rehype plugins access to user frontmatter via frontmatter injection. This means `data.astro.frontmatter` is now the _complete_ Markdown or MDX document's frontmatter, rather than an empty object.
8
+
9
+ This allows plugin authors to modify existing frontmatter, or compute new properties based on other properties. For example, say you want to compute a full image URL based on an `imageSrc` slug in your document frontmatter:
10
+
11
+ ```ts
12
+ export function remarkInjectSocialImagePlugin() {
13
+ return function (tree, file) {
14
+ const { frontmatter } = file.data.astro;
15
+ frontmatter.socialImageSrc = new URL(frontmatter.imageSrc, 'https://my-blog.com/').pathname;
16
+ };
17
+ }
18
+ ```
19
+
20
+ #### Content Collections - new `remarkPluginFrontmatter` property
21
+
22
+ We have changed _inject_ frontmatter to _modify_ frontmatter in our docs to improve discoverability. This is based on support forum feedback, where "injection" is rarely the term used.
23
+
24
+ To reflect this, the `injectedFrontmatter` property has been renamed to `remarkPluginFrontmatter`. This should clarify this plugin is still separate from the `data` export Content Collections expose today.
25
+
26
+ #### Migration instructions
27
+
28
+ Plugin authors should now **check for user frontmatter when applying defaults.**
29
+
30
+ For example, say a remark plugin wants to apply a default `title` if none is present. Add a conditional to check if the property is present, and update if none exists:
31
+
32
+ ```diff
33
+ export function remarkInjectTitlePlugin() {
34
+ return function (tree, file) {
35
+ const { frontmatter } = file.data.astro;
36
+ + if (!frontmatter.title) {
37
+ frontmatter.title = 'Default title';
38
+ + }
39
+ }
40
+ }
41
+ ```
42
+
43
+ This differs from previous behavior, where a Markdown file's frontmatter would _always_ override frontmatter injected via remark or reype.
44
+
45
+ - [#5684](https://github.com/withastro/astro/pull/5684) [`a9c292026`](https://github.com/withastro/astro/commit/a9c2920264e36cc5dc05f4adc1912187979edb0d) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Refine Markdown and MDX configuration options for ease-of-use.
46
+
47
+ #### Markdown
48
+
49
+ - **Remove `remark-smartypants`** from Astro's default Markdown plugins.
50
+ - **Replace the `extendDefaultPlugins` option** with a simplified `gfm` boolean. This is enabled by default, and can be disabled to remove GitHub-Flavored Markdown.
51
+ - Ensure GitHub-Flavored Markdown is applied whether or not custom `remarkPlugins` or `rehypePlugins` are configured. If you want to apply custom plugins _and_ remove GFM, manually set `gfm: false` in your config.
52
+
53
+ #### MDX
54
+
55
+ - Support _all_ Markdown configuration options (except `drafts`) from your MDX integration config. This includes `syntaxHighlighting` and `shikiConfig` options to further customize the MDX renderer.
56
+ - Simplify `extendDefaults` to an `extendMarkdownConfig` option. MDX options will default to their equivalent in your Markdown config. By setting `extendMarkdownConfig` to false, you can "eject" to set your own syntax highlighting, plugins, and more.
57
+
58
+ #### Migration
59
+
60
+ To preserve your existing Markdown and MDX setup, you may need some configuration changes:
61
+
62
+ ##### Smartypants manual installation
63
+
64
+ [Smartypants](https://github.com/silvenon/remark-smartypants) has been removed from Astro's default setup. If you rely on this plugin, [install `remark-smartypants`](https://github.com/silvenon/remark-smartypants#installing) and apply to your `astro.config.*`:
65
+
66
+ ```diff
67
+ // astro.config.mjs
68
+ import { defineConfig } from 'astro/config';
69
+ + import smartypants from 'remark-smartypants';
70
+
71
+ export default defineConfig({
72
+ markdown: {
73
+ + remarkPlugins: [smartypants],
74
+ }
75
+ });
76
+ ```
77
+
78
+ ##### Migrate `extendDefaultPlugins` to `gfm`
79
+
80
+ You may have disabled Astro's built-in plugins (GitHub-Flavored Markdown and Smartypants) with the `extendDefaultPlugins` option. Since Smartypants has been removed, this has been renamed to `gfm`.
81
+
82
+ ```diff
83
+ // astro.config.mjs
84
+ import { defineConfig } from 'astro/config';
85
+
86
+ export default defineConfig({
87
+ markdown: {
88
+ - extendDefaultPlugins: false,
89
+ + gfm: false,
90
+ }
91
+ });
92
+ ```
93
+
94
+ Additionally, applying remark and rehype plugins **no longer disables** `gfm`. You will need to opt-out manually by setting `gfm` to `false`.
95
+
96
+ ##### Migrate MDX's `extendPlugins` to `extendMarkdownConfig`
97
+
98
+ You may have used the `extendPlugins` option to manage plugin defaults in MDX. This has been replaced by 2 flags:
99
+
100
+ - `extendMarkdownConfig` (`true` by default) to toggle Markdown config inheritance. This replaces the `extendPlugins: 'markdown'` option.
101
+ - `gfm` (`true` by default) to toggle GitHub-Flavored Markdown in MDX. This replaces the `extendPlugins: 'defaults'` option.
102
+
3
103
  ## 1.2.0
4
104
 
5
105
  ### Minor Changes
@@ -0,0 +1,8 @@
1
+ import type { Data, VFile } from 'vfile';
2
+ import type { MarkdownAstroData } from './types.js';
3
+ export declare class InvalidAstroDataError extends TypeError {
4
+ }
5
+ export declare function safelyGetAstroData(vfileData: Data): MarkdownAstroData | InvalidAstroDataError;
6
+ export declare function toRemarkInitializeAstroData({ userFrontmatter, }: {
7
+ userFrontmatter: Record<string, any>;
8
+ }): () => (tree: any, vfile: VFile) => void;
@@ -0,0 +1,35 @@
1
+ function isValidAstroData(obj) {
2
+ if (typeof obj === "object" && obj !== null && obj.hasOwnProperty("frontmatter")) {
3
+ const { frontmatter } = obj;
4
+ try {
5
+ JSON.stringify(frontmatter);
6
+ } catch {
7
+ return false;
8
+ }
9
+ return typeof frontmatter === "object" && frontmatter !== null;
10
+ }
11
+ return false;
12
+ }
13
+ class InvalidAstroDataError extends TypeError {
14
+ }
15
+ function safelyGetAstroData(vfileData) {
16
+ const { astro } = vfileData;
17
+ if (!astro || !isValidAstroData(astro)) {
18
+ return new InvalidAstroDataError();
19
+ }
20
+ return astro;
21
+ }
22
+ function toRemarkInitializeAstroData({
23
+ userFrontmatter
24
+ }) {
25
+ return () => function(tree, vfile) {
26
+ if (!vfile.data.astro) {
27
+ vfile.data.astro = { frontmatter: userFrontmatter };
28
+ }
29
+ };
30
+ }
31
+ export {
32
+ InvalidAstroDataError,
33
+ safelyGetAstroData,
34
+ toRemarkInitializeAstroData
35
+ };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import type { MarkdownRenderingOptions, MarkdownRenderingResult } from './types';
1
+ import type { AstroMarkdownOptions, MarkdownRenderingOptions, MarkdownRenderingResult } from './types';
2
2
  export { rehypeHeadingIds } from './rehype-collect-headings.js';
3
3
  export * from './types.js';
4
- export declare const DEFAULT_REMARK_PLUGINS: string[];
5
- export declare const DEFAULT_REHYPE_PLUGINS: never[];
4
+ export declare const markdownConfigDefaults: Omit<Required<AstroMarkdownOptions>, 'drafts'>;
6
5
  /** Shared utility for rendering markdown */
7
6
  export declare function renderMarkdown(content: string, opts: MarkdownRenderingOptions): Promise<MarkdownRenderingResult>;
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { toRemarkInitializeAstroData } from "./frontmatter-injection.js";
1
2
  import { loadPlugins } from "./load-plugins.js";
2
3
  import { rehypeHeadingIds } from "./rehype-collect-headings.js";
3
4
  import rehypeEscape from "./rehype-escape.js";
@@ -6,7 +7,6 @@ import rehypeIslands from "./rehype-islands.js";
6
7
  import rehypeJsx from "./rehype-jsx.js";
7
8
  import toRemarkContentRelImageError from "./remark-content-rel-image-error.js";
8
9
  import remarkEscape from "./remark-escape.js";
9
- import { remarkInitializeAstroData } from "./remark-initialize-astro-data.js";
10
10
  import remarkMarkAndUnravel from "./remark-mark-and-unravel.js";
11
11
  import remarkMdxish from "./remark-mdxish.js";
12
12
  import remarkPrism from "./remark-prism.js";
@@ -15,34 +15,45 @@ import remarkShiki from "./remark-shiki.js";
15
15
  import remarkUnwrap from "./remark-unwrap.js";
16
16
  import rehypeRaw from "rehype-raw";
17
17
  import rehypeStringify from "rehype-stringify";
18
+ import remarkGfm from "remark-gfm";
18
19
  import markdown from "remark-parse";
19
20
  import markdownToHtml from "remark-rehype";
20
21
  import { unified } from "unified";
21
22
  import { VFile } from "vfile";
22
23
  import { rehypeHeadingIds as rehypeHeadingIds2 } from "./rehype-collect-headings.js";
23
24
  export * from "./types.js";
24
- const DEFAULT_REMARK_PLUGINS = ["remark-gfm", "remark-smartypants"];
25
- const DEFAULT_REHYPE_PLUGINS = [];
25
+ const markdownConfigDefaults = {
26
+ syntaxHighlight: "shiki",
27
+ shikiConfig: {
28
+ langs: [],
29
+ theme: "github-dark",
30
+ wrap: false
31
+ },
32
+ remarkPlugins: [],
33
+ rehypePlugins: [],
34
+ remarkRehype: {},
35
+ gfm: true
36
+ };
26
37
  async function renderMarkdown(content, opts) {
27
38
  var _a;
28
39
  let {
29
40
  fileURL,
30
- syntaxHighlight = "shiki",
31
- shikiConfig = {},
32
- remarkPlugins = [],
33
- rehypePlugins = [],
34
- remarkRehype = {},
35
- extendDefaultPlugins = false,
41
+ syntaxHighlight = markdownConfigDefaults.syntaxHighlight,
42
+ shikiConfig = markdownConfigDefaults.shikiConfig,
43
+ remarkPlugins = markdownConfigDefaults.remarkPlugins,
44
+ rehypePlugins = markdownConfigDefaults.rehypePlugins,
45
+ remarkRehype = markdownConfigDefaults.remarkRehype,
46
+ gfm = markdownConfigDefaults.gfm,
36
47
  isAstroFlavoredMd = false,
37
48
  isExperimentalContentCollections = false,
38
- contentDir
49
+ contentDir,
50
+ frontmatter: userFrontmatter = {}
39
51
  } = opts;
40
52
  const input = new VFile({ value: content, path: fileURL });
41
53
  const scopedClassName = (_a = opts.$) == null ? void 0 : _a.scopedClassName;
42
- let parser = unified().use(markdown).use(remarkInitializeAstroData).use(isAstroFlavoredMd ? [remarkMdxish, remarkMarkAndUnravel, remarkUnwrap, remarkEscape] : []);
43
- if (extendDefaultPlugins || remarkPlugins.length === 0 && rehypePlugins.length === 0) {
44
- remarkPlugins = [...DEFAULT_REMARK_PLUGINS, ...remarkPlugins];
45
- rehypePlugins = [...DEFAULT_REHYPE_PLUGINS, ...rehypePlugins];
54
+ let parser = unified().use(markdown).use(toRemarkInitializeAstroData({ userFrontmatter })).use(isAstroFlavoredMd ? [remarkMdxish, remarkMarkAndUnravel, remarkUnwrap, remarkEscape] : []);
55
+ if (gfm) {
56
+ parser.use(remarkGfm);
46
57
  }
47
58
  const loadedRemarkPlugins = await Promise.all(loadPlugins(remarkPlugins));
48
59
  const loadedRehypePlugins = await Promise.all(loadPlugins(rehypePlugins));
@@ -115,8 +126,7 @@ ${err.message}`;
115
126
  return wrappedError;
116
127
  }
117
128
  export {
118
- DEFAULT_REHYPE_PLUGINS,
119
- DEFAULT_REMARK_PLUGINS,
129
+ markdownConfigDefaults,
120
130
  rehypeHeadingIds2 as rehypeHeadingIds,
121
131
  renderMarkdown
122
132
  };
@@ -0,0 +1 @@
1
+ export { InvalidAstroDataError, safelyGetAstroData, toRemarkInitializeAstroData, } from './frontmatter-injection.js';
@@ -0,0 +1,10 @@
1
+ import {
2
+ InvalidAstroDataError,
3
+ safelyGetAstroData,
4
+ toRemarkInitializeAstroData
5
+ } from "./frontmatter-injection.js";
6
+ export {
7
+ InvalidAstroDataError,
8
+ safelyGetAstroData,
9
+ toRemarkInitializeAstroData
10
+ };
package/dist/types.d.ts CHANGED
@@ -5,14 +5,16 @@ import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
5
5
  import type * as unified from 'unified';
6
6
  import type { VFile } from 'vfile';
7
7
  export type { Node } from 'unist';
8
+ export declare type MarkdownAstroData = {
9
+ frontmatter: Record<string, any>;
10
+ };
8
11
  export declare type RemarkPlugin<PluginParameters extends any[] = any[]> = unified.Plugin<PluginParameters, mdast.Root>;
9
12
  export declare type RemarkPlugins = (string | [string, any] | RemarkPlugin | [RemarkPlugin, any])[];
10
13
  export declare type RehypePlugin<PluginParameters extends any[] = any[]> = unified.Plugin<PluginParameters, hast.Root>;
11
14
  export declare type RehypePlugins = (string | [string, any] | RehypePlugin | [RehypePlugin, any])[];
12
15
  export declare type RemarkRehype = Omit<RemarkRehypeOptions, 'handlers' | 'unknownHandler'> & {
13
- handlers: typeof Handlers;
14
- } & {
15
- handler: typeof Handler;
16
+ handlers?: typeof Handlers;
17
+ handler?: typeof Handler;
16
18
  };
17
19
  export interface ShikiConfig {
18
20
  langs?: ILanguageRegistration[];
@@ -20,14 +22,13 @@ export interface ShikiConfig {
20
22
  wrap?: boolean | null;
21
23
  }
22
24
  export interface AstroMarkdownOptions {
23
- mode?: 'md' | 'mdx';
24
25
  drafts?: boolean;
25
26
  syntaxHighlight?: 'shiki' | 'prism' | false;
26
27
  shikiConfig?: ShikiConfig;
27
28
  remarkPlugins?: RemarkPlugins;
28
29
  rehypePlugins?: RehypePlugins;
29
30
  remarkRehype?: RemarkRehype;
30
- extendDefaultPlugins?: boolean;
31
+ gfm?: boolean;
31
32
  }
32
33
  export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
33
34
  /** @internal */
@@ -41,6 +42,8 @@ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
41
42
  isExperimentalContentCollections?: boolean;
42
43
  /** Used to prevent relative image imports from `src/content/` */
43
44
  contentDir: URL;
45
+ /** Used for frontmatter injection plugins */
46
+ frontmatter?: Record<string, any>;
44
47
  }
45
48
  export interface MarkdownHeading {
46
49
  depth: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "1.2.0",
3
+ "version": "2.0.0-beta.0",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -13,7 +13,8 @@
13
13
  "homepage": "https://astro.build",
14
14
  "main": "./dist/index.js",
15
15
  "exports": {
16
- ".": "./dist/index.js"
16
+ ".": "./dist/index.js",
17
+ "./dist/internal.js": "./dist/internal.js"
17
18
  },
18
19
  "dependencies": {
19
20
  "@astrojs/micromark-extension-mdx-jsx": "^1.0.3",
@@ -34,7 +35,6 @@
34
35
  "remark-gfm": "^3.0.1",
35
36
  "remark-parse": "^10.0.1",
36
37
  "remark-rehype": "^10.1.0",
37
- "remark-smartypants": "^2.0.0",
38
38
  "shiki": "^0.11.1",
39
39
  "unified": "^10.1.2",
40
40
  "unist-util-map": "^3.1.1",
@@ -0,0 +1,41 @@
1
+ import type { Data, VFile } from 'vfile';
2
+ import type { MarkdownAstroData } from './types.js';
3
+
4
+ function isValidAstroData(obj: unknown): obj is MarkdownAstroData {
5
+ if (typeof obj === 'object' && obj !== null && obj.hasOwnProperty('frontmatter')) {
6
+ const { frontmatter } = obj as any;
7
+ try {
8
+ // ensure frontmatter is JSON-serializable
9
+ JSON.stringify(frontmatter);
10
+ } catch {
11
+ return false;
12
+ }
13
+ return typeof frontmatter === 'object' && frontmatter !== null;
14
+ }
15
+ return false;
16
+ }
17
+
18
+ export class InvalidAstroDataError extends TypeError {}
19
+
20
+ export function safelyGetAstroData(vfileData: Data): MarkdownAstroData | InvalidAstroDataError {
21
+ const { astro } = vfileData;
22
+
23
+ if (!astro || !isValidAstroData(astro)) {
24
+ return new InvalidAstroDataError();
25
+ }
26
+
27
+ return astro;
28
+ }
29
+
30
+ export function toRemarkInitializeAstroData({
31
+ userFrontmatter,
32
+ }: {
33
+ userFrontmatter: Record<string, any>;
34
+ }) {
35
+ return () =>
36
+ function (tree: any, vfile: VFile) {
37
+ if (!vfile.data.astro) {
38
+ vfile.data.astro = { frontmatter: userFrontmatter };
39
+ }
40
+ };
41
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,11 @@
1
- import type { MarkdownRenderingOptions, MarkdownRenderingResult, MarkdownVFile } from './types';
2
-
1
+ import type {
2
+ AstroMarkdownOptions,
3
+ MarkdownRenderingOptions,
4
+ MarkdownRenderingResult,
5
+ MarkdownVFile,
6
+ } from './types';
7
+
8
+ import { toRemarkInitializeAstroData } from './frontmatter-injection.js';
3
9
  import { loadPlugins } from './load-plugins.js';
4
10
  import { rehypeHeadingIds } from './rehype-collect-headings.js';
5
11
  import rehypeEscape from './rehype-escape.js';
@@ -8,7 +14,6 @@ import rehypeIslands from './rehype-islands.js';
8
14
  import rehypeJsx from './rehype-jsx.js';
9
15
  import toRemarkContentRelImageError from './remark-content-rel-image-error.js';
10
16
  import remarkEscape from './remark-escape.js';
11
- import { remarkInitializeAstroData } from './remark-initialize-astro-data.js';
12
17
  import remarkMarkAndUnravel from './remark-mark-and-unravel.js';
13
18
  import remarkMdxish from './remark-mdxish.js';
14
19
  import remarkPrism from './remark-prism.js';
@@ -18,6 +23,7 @@ import remarkUnwrap from './remark-unwrap.js';
18
23
 
19
24
  import rehypeRaw from 'rehype-raw';
20
25
  import rehypeStringify from 'rehype-stringify';
26
+ import remarkGfm from 'remark-gfm';
21
27
  import markdown from 'remark-parse';
22
28
  import markdownToHtml from 'remark-rehype';
23
29
  import { unified } from 'unified';
@@ -26,8 +32,18 @@ import { VFile } from 'vfile';
26
32
  export { rehypeHeadingIds } from './rehype-collect-headings.js';
27
33
  export * from './types.js';
28
34
 
29
- export const DEFAULT_REMARK_PLUGINS = ['remark-gfm', 'remark-smartypants'];
30
- export const DEFAULT_REHYPE_PLUGINS = [];
35
+ export const markdownConfigDefaults: Omit<Required<AstroMarkdownOptions>, 'drafts'> = {
36
+ syntaxHighlight: 'shiki',
37
+ shikiConfig: {
38
+ langs: [],
39
+ theme: 'github-dark',
40
+ wrap: false,
41
+ },
42
+ remarkPlugins: [],
43
+ rehypePlugins: [],
44
+ remarkRehype: {},
45
+ gfm: true,
46
+ };
31
47
 
32
48
  /** Shared utility for rendering markdown */
33
49
  export async function renderMarkdown(
@@ -36,27 +52,27 @@ export async function renderMarkdown(
36
52
  ): Promise<MarkdownRenderingResult> {
37
53
  let {
38
54
  fileURL,
39
- syntaxHighlight = 'shiki',
40
- shikiConfig = {},
41
- remarkPlugins = [],
42
- rehypePlugins = [],
43
- remarkRehype = {},
44
- extendDefaultPlugins = false,
55
+ syntaxHighlight = markdownConfigDefaults.syntaxHighlight,
56
+ shikiConfig = markdownConfigDefaults.shikiConfig,
57
+ remarkPlugins = markdownConfigDefaults.remarkPlugins,
58
+ rehypePlugins = markdownConfigDefaults.rehypePlugins,
59
+ remarkRehype = markdownConfigDefaults.remarkRehype,
60
+ gfm = markdownConfigDefaults.gfm,
45
61
  isAstroFlavoredMd = false,
46
62
  isExperimentalContentCollections = false,
47
63
  contentDir,
64
+ frontmatter: userFrontmatter = {},
48
65
  } = opts;
49
66
  const input = new VFile({ value: content, path: fileURL });
50
67
  const scopedClassName = opts.$?.scopedClassName;
51
68
 
52
69
  let parser = unified()
53
70
  .use(markdown)
54
- .use(remarkInitializeAstroData)
71
+ .use(toRemarkInitializeAstroData({ userFrontmatter }))
55
72
  .use(isAstroFlavoredMd ? [remarkMdxish, remarkMarkAndUnravel, remarkUnwrap, remarkEscape] : []);
56
73
 
57
- if (extendDefaultPlugins || (remarkPlugins.length === 0 && rehypePlugins.length === 0)) {
58
- remarkPlugins = [...DEFAULT_REMARK_PLUGINS, ...remarkPlugins];
59
- rehypePlugins = [...DEFAULT_REHYPE_PLUGINS, ...rehypePlugins];
74
+ if (gfm) {
75
+ parser.use(remarkGfm);
60
76
  }
61
77
 
62
78
  const loadedRemarkPlugins = await Promise.all(loadPlugins(remarkPlugins));
@@ -0,0 +1,5 @@
1
+ export {
2
+ InvalidAstroDataError,
3
+ safelyGetAstroData,
4
+ toRemarkInitializeAstroData,
5
+ } from './frontmatter-injection.js';
package/src/types.ts CHANGED
@@ -11,6 +11,10 @@ import type { VFile } from 'vfile';
11
11
 
12
12
  export type { Node } from 'unist';
13
13
 
14
+ export type MarkdownAstroData = {
15
+ frontmatter: Record<string, any>;
16
+ };
17
+
14
18
  export type RemarkPlugin<PluginParameters extends any[] = any[]> = unified.Plugin<
15
19
  PluginParameters,
16
20
  mdast.Root
@@ -26,8 +30,9 @@ export type RehypePlugin<PluginParameters extends any[] = any[]> = unified.Plugi
26
30
  export type RehypePlugins = (string | [string, any] | RehypePlugin | [RehypePlugin, any])[];
27
31
 
28
32
  export type RemarkRehype = Omit<RemarkRehypeOptions, 'handlers' | 'unknownHandler'> & {
29
- handlers: typeof Handlers;
30
- } & { handler: typeof Handler };
33
+ handlers?: typeof Handlers;
34
+ handler?: typeof Handler;
35
+ };
31
36
 
32
37
  export interface ShikiConfig {
33
38
  langs?: ILanguageRegistration[];
@@ -36,14 +41,13 @@ export interface ShikiConfig {
36
41
  }
37
42
 
38
43
  export interface AstroMarkdownOptions {
39
- mode?: 'md' | 'mdx';
40
44
  drafts?: boolean;
41
45
  syntaxHighlight?: 'shiki' | 'prism' | false;
42
46
  shikiConfig?: ShikiConfig;
43
47
  remarkPlugins?: RemarkPlugins;
44
48
  rehypePlugins?: RehypePlugins;
45
49
  remarkRehype?: RemarkRehype;
46
- extendDefaultPlugins?: boolean;
50
+ gfm?: boolean;
47
51
  }
48
52
 
49
53
  export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
@@ -58,6 +62,8 @@ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
58
62
  isExperimentalContentCollections?: boolean;
59
63
  /** Used to prevent relative image imports from `src/content/` */
60
64
  contentDir: URL;
65
+ /** Used for frontmatter injection plugins */
66
+ frontmatter?: Record<string, any>;
61
67
  }
62
68
 
63
69
  export interface MarkdownHeading {
@@ -1,2 +0,0 @@
1
- import type { VFile } from 'vfile';
2
- export declare function remarkInitializeAstroData(): (tree: any, vfile: VFile) => void;
@@ -1,10 +0,0 @@
1
- function remarkInitializeAstroData() {
2
- return function(tree, vfile) {
3
- if (!vfile.data.astro) {
4
- vfile.data.astro = { frontmatter: {} };
5
- }
6
- };
7
- }
8
- export {
9
- remarkInitializeAstroData
10
- };
@@ -1,9 +0,0 @@
1
- import type { VFile } from 'vfile';
2
-
3
- export function remarkInitializeAstroData() {
4
- return function (tree: any, vfile: VFile) {
5
- if (!vfile.data.astro) {
6
- vfile.data.astro = { frontmatter: {} };
7
- }
8
- };
9
- }