summaryrefslogtreecommitdiff
path: root/packages/markdown/remark/src
diff options
context:
space:
mode:
authorGravatar gtnbssn <gaetan.boisson@gmail.com> 2022-08-26 04:30:16 +0800
committerGravatar GitHub <noreply@github.com> 2022-08-25 16:30:16 -0400
commit839097c84e830542c17c18d8337a88de8885c356 (patch)
tree16fb1eba3ffc0e49096cd3d1c38d3eac94b5d0e1 /packages/markdown/remark/src
parentb680c3eb97b3bdd271dd5e0e848e3dba4221f140 (diff)
downloadastro-839097c84e830542c17c18d8337a88de8885c356.tar.gz
astro-839097c84e830542c17c18d8337a88de8885c356.tar.zst
astro-839097c84e830542c17c18d8337a88de8885c356.zip
make Remark rehype options available in astro config (#4138)
* make remark-rehype config available in astro.config.mjs * add test for remark-rehype config, checks that footnotes can be translated * update lockfile to take the added test into account * omit handlers and unkownHandler from the RemarkRehype type * define RemarkRehype with proper references to the handler and handlers types * formatting * changeset Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> Co-authored-by: Matthew Phillips <matthew@skypack.dev>
Diffstat (limited to 'packages/markdown/remark/src')
-rw-r--r--packages/markdown/remark/src/index.ts2
-rw-r--r--packages/markdown/remark/src/types.ts10
2 files changed, 12 insertions, 0 deletions
diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts
index a50b3ad19..da64a5459 100644
--- a/packages/markdown/remark/src/index.ts
+++ b/packages/markdown/remark/src/index.ts
@@ -38,6 +38,7 @@ export async function renderMarkdown(
shikiConfig = {},
remarkPlugins = [],
rehypePlugins = [],
+ remarkRehype = {},
isAstroFlavoredMd = false,
} = opts;
const input = new VFile({ value: content, path: fileURL });
@@ -85,6 +86,7 @@ export async function renderMarkdown(
'mdxTextExpression',
]
: [],
+ ...remarkRehype,
},
],
]);
diff --git a/packages/markdown/remark/src/types.ts b/packages/markdown/remark/src/types.ts
index 3569e8d04..bf3d10904 100644
--- a/packages/markdown/remark/src/types.ts
+++ b/packages/markdown/remark/src/types.ts
@@ -1,6 +1,11 @@
import type * as hast from 'hast';
import type * as mdast from 'mdast';
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
+import type {
+ Options as RemarkRehypeOptions,
+ all as Handlers,
+ one as Handler,
+} from 'remark-rehype';
import type * as unified from 'unified';
import type { VFile } from 'vfile';
@@ -20,6 +25,10 @@ export type RehypePlugin<PluginParameters extends any[] = any[]> = unified.Plugi
export type RehypePlugins = (string | [string, any] | RehypePlugin | [RehypePlugin, any])[];
+export type RemarkRehype = Omit<RemarkRehypeOptions, 'handlers' | 'unknownHandler'> & {
+ handlers: typeof Handlers;
+} & { handler: typeof Handler };
+
export interface ShikiConfig {
langs?: ILanguageRegistration[];
theme?: Theme | IThemeRegistration;
@@ -33,6 +42,7 @@ export interface AstroMarkdownOptions {
shikiConfig?: ShikiConfig;
remarkPlugins?: RemarkPlugins;
rehypePlugins?: RehypePlugins;
+ remarkRehype?: RemarkRehype;
}
export interface MarkdownRenderingOptions extends AstroMarkdownOptions {