From 6699cedc004333017dbfb98bfbdaa8787be72386 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Thu, 30 Jul 2026 04:51:20 +0530 Subject: [PATCH] refactor(markdown): fold highlight typing into MarkdownRenderer Expose the any-typed highlight escape hatch on the exported MarkdownRenderer type and accept it in the preConfig/config hooks, instead of special-casing only the internal singleton. Co-Authored-By: Claude Fable 5 --- src/node/markdown/markdown.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/node/markdown/markdown.ts b/src/node/markdown/markdown.ts index 6845bbe8..7ffe1e6d 100644 --- a/src/node/markdown/markdown.ts +++ b/src/node/markdown/markdown.ts @@ -69,17 +69,24 @@ export type ThemeOptions = dark: ThemeRegistrationAny | BuiltinTheme } +// highlight is marked as any to avoid type conflicts with plugins expecting +// regular markdown-it which has sync highlight function. Such plugins will fail +// if they access highlight directly but currently none of the ones we use do that. +export type MarkdownRenderer = MarkdownItAsync & { + options: { highlight?: any } +} + export interface MarkdownOptions extends MarkdownItAsyncOptions { /* ==================== General Options ==================== */ /** * Configure the markdown-it instance before any plugins are applied. */ - preConfig?: (md: MarkdownItAsync) => Awaitable + preConfig?: (md: MarkdownRenderer) => Awaitable /** * Configure the markdown-it instance after all built-in plugins are applied. */ - config?: (md: MarkdownItAsync) => Awaitable + config?: (md: MarkdownRenderer) => Awaitable /** * Disable cache (experimental) */ @@ -309,8 +316,6 @@ export interface MarkdownOptions extends MarkdownItAsyncOptions { sfc?: SfcPluginOptions } -export type MarkdownRenderer = MarkdownItAsync - // folds `locales..markdown` entries from the site config into // `MarkdownOptions.locales` so per-locale strings reach the renderer - // site config entries win over directly passed ones @@ -327,10 +332,7 @@ export function mergeMarkdownLocales( return { ...options, locales: merged } } -// highlight is marked as any to avoid type conflicts with plugins expecting -// regular markdown-it which has sync highlight function. Such plugins will fail -// if they access highlight directly but currently none of the ones we use do that. -let md: (MarkdownRenderer & { options: { highlight?: any } }) | undefined +let md: MarkdownRenderer | undefined let _disposeHighlighter: (() => void) | undefined export function disposeMdItInstance() {