From 02f9d84d22229b12fa8a9595615de5f9adc4e048 Mon Sep 17 00:00:00 2001
From: bluwy <bjornlu.dev@gmail.com>
Date: Tue, 21 Nov 2023 15:37:31 +0800
Subject: [PATCH] Fix RemarkRehype types

---
 .changeset/khaki-fans-sell.md         | 5 +++++
 packages/markdown/remark/package.json | 1 -
 packages/markdown/remark/src/index.ts | 2 +-
 packages/markdown/remark/src/types.ts | 9 +--------
 pnpm-lock.yaml                        | 3 ---
 5 files changed, 7 insertions(+), 13 deletions(-)
 create mode 100644 .changeset/khaki-fans-sell.md

diff --git a/.changeset/khaki-fans-sell.md b/.changeset/khaki-fans-sell.md
new file mode 100644
index 000000000000..f6d84bdaedac
--- /dev/null
+++ b/.changeset/khaki-fans-sell.md
@@ -0,0 +1,5 @@
+---
+'@astrojs/markdown-remark': patch
+---
+
+Fixes `RemarkRehype` type's `handler` and `handlers` properties
diff --git a/packages/markdown/remark/package.json b/packages/markdown/remark/package.json
index b465ec4f29b3..5bae632fce46 100644
--- a/packages/markdown/remark/package.json
+++ b/packages/markdown/remark/package.json
@@ -35,7 +35,6 @@
     "github-slugger": "^2.0.0",
     "import-meta-resolve": "^4.0.0",
     "mdast-util-definitions": "^6.0.0",
-    "mdast-util-to-hast": "13.0.2",
     "rehype-raw": "^7.0.0",
     "rehype-stringify": "^10.0.0",
     "remark-gfm": "^4.0.0",
diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts
index a60ab88c0ef5..d42ce480c308 100644
--- a/packages/markdown/remark/src/index.ts
+++ b/packages/markdown/remark/src/index.ts
@@ -102,7 +102,7 @@ export async function createMarkdownProcessor(
 	}
 
 	// Remark -> Rehype
-	parser.use(remarkRehype as any, {
+	parser.use(remarkRehype, {
 		allowDangerousHtml: true,
 		passThrough: [],
 		...remarkRehypeOptions,
diff --git a/packages/markdown/remark/src/types.ts b/packages/markdown/remark/src/types.ts
index d0a6a13c2b10..b25e9227130e 100644
--- a/packages/markdown/remark/src/types.ts
+++ b/packages/markdown/remark/src/types.ts
@@ -1,7 +1,6 @@
 import type * as hast from 'hast';
 import type * as mdast from 'mdast';
 import type { Options as RemarkRehypeOptions } from 'remark-rehype';
-import type { State } from 'mdast-util-to-hast';
 import type {
 	BuiltinTheme,
 	LanguageRegistration,
@@ -11,9 +10,6 @@ import type {
 import type * as unified from 'unified';
 import type { VFile } from 'vfile';
 
-type Handler = State['one'];
-type Handlers = State['all'];
-
 export type { Node } from 'unist';
 
 export type MarkdownAstroData = {
@@ -34,10 +30,7 @@ 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?: Handlers;
-	handler?: Handler;
-};
+export type RemarkRehype = RemarkRehypeOptions;
 
 export interface ShikiConfig {
 	langs?: LanguageRegistration[];
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 60e906a70e89..fb9dbe3e8db9 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -4905,9 +4905,6 @@ importers:
       mdast-util-definitions:
         specifier: ^6.0.0
         version: 6.0.0
-      mdast-util-to-hast:
-        specifier: 13.0.2
-        version: 13.0.2
       rehype-raw:
         specifier: ^7.0.0
         version: 7.0.0