diff options
Diffstat (limited to 'packages/markdown/remark/src')
-rw-r--r-- | packages/markdown/remark/src/frontmatter-injection.ts | 16 | ||||
-rw-r--r-- | packages/markdown/remark/src/index.ts | 43 | ||||
-rw-r--r-- | packages/markdown/remark/src/internal.ts | 6 | ||||
-rw-r--r-- | packages/markdown/remark/src/types.ts | 12 |
4 files changed, 6 insertions, 71 deletions
diff --git a/packages/markdown/remark/src/frontmatter-injection.ts b/packages/markdown/remark/src/frontmatter-injection.ts index 4828873fd..91b98ebcb 100644 --- a/packages/markdown/remark/src/frontmatter-injection.ts +++ b/packages/markdown/remark/src/frontmatter-injection.ts @@ -32,19 +32,3 @@ export function setVfileFrontmatter(vfile: VFile, frontmatter: Record<string, an vfile.data.astro ??= {}; (vfile.data.astro as any).frontmatter = frontmatter; } - -/** - * @deprecated Use `setVfileFrontmatter` instead - */ -export function toRemarkInitializeAstroData({ - userFrontmatter, -}: { - userFrontmatter: Record<string, any>; -}) { - return () => - function (tree: any, vfile: VFile) { - if (!vfile.data.astro) { - vfile.data.astro = { frontmatter: userFrontmatter }; - } - }; -} diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts index a60ab88c0..143015847 100644 --- a/packages/markdown/remark/src/index.ts +++ b/packages/markdown/remark/src/index.ts @@ -1,10 +1,4 @@ -import type { - AstroMarkdownOptions, - MarkdownProcessor, - MarkdownRenderingOptions, - MarkdownRenderingResult, - MarkdownVFile, -} from './types.js'; +import type { AstroMarkdownOptions, MarkdownProcessor, MarkdownVFile } from './types.js'; import { InvalidAstroDataError, @@ -35,7 +29,7 @@ export { remarkShiki } from './remark-shiki.js'; export { createShikiHighlighter, replaceCssVariables, type ShikiHighlighter } from './shiki.js'; export * from './types.js'; -export const markdownConfigDefaults: Omit<Required<AstroMarkdownOptions>, 'drafts'> = { +export const markdownConfigDefaults: Required<AstroMarkdownOptions> = { syntaxHighlight: 'shiki', shikiConfig: { langs: [], @@ -102,7 +96,7 @@ export async function createMarkdownProcessor( } // Remark -> Rehype - parser.use(remarkRehype as any, { + parser.use(remarkRehype, { allowDangerousHtml: true, passThrough: [], ...remarkRehypeOptions, @@ -150,42 +144,11 @@ export async function createMarkdownProcessor( imagePaths: result.data.imagePaths ?? new Set(), frontmatter: astroData.frontmatter ?? {}, }, - // Compat for `renderMarkdown` only. Do not use! - __renderMarkdownCompat: { - result, - }, }; }, }; } -/** - * Shared utility for rendering markdown - * - * @deprecated Use `createMarkdownProcessor` instead for better performance - */ -export async function renderMarkdown( - content: string, - opts: MarkdownRenderingOptions -): Promise<MarkdownRenderingResult> { - const processor = await createMarkdownProcessor(opts); - - const result = await processor.render(content, { - fileURL: opts.fileURL, - frontmatter: opts.frontmatter, - }); - - return { - code: result.code, - metadata: { - headings: result.metadata.headings, - source: content, - html: result.code, - }, - vfile: (result as any).__renderMarkdownCompat.result, - }; -} - function prefixError(err: any, prefix: string) { // If the error is an object with a `message` property, attempt to prefix the message if (err?.message) { diff --git a/packages/markdown/remark/src/internal.ts b/packages/markdown/remark/src/internal.ts index 0ab7e34bb..6201ef62f 100644 --- a/packages/markdown/remark/src/internal.ts +++ b/packages/markdown/remark/src/internal.ts @@ -1,5 +1 @@ -export { - InvalidAstroDataError, - safelyGetAstroData, - toRemarkInitializeAstroData, -} from './frontmatter-injection.js'; +export { InvalidAstroDataError, safelyGetAstroData } from './frontmatter-injection.js'; diff --git a/packages/markdown/remark/src/types.ts b/packages/markdown/remark/src/types.ts index 7038e2425..ab5af8ed1 100644 --- a/packages/markdown/remark/src/types.ts +++ b/packages/markdown/remark/src/types.ts @@ -1,10 +1,6 @@ import type * as hast from 'hast'; import type * as mdast from 'mdast'; -import type { - one as Handler, - all as Handlers, - Options as RemarkRehypeOptions, -} from 'remark-rehype'; +import type { Options as RemarkRehypeOptions } from 'remark-rehype'; import type { BuiltinTheme, LanguageRegistration, @@ -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?: typeof Handlers; - handler?: typeof Handler; -}; +export type RemarkRehype = RemarkRehypeOptions; export interface ShikiConfig { langs?: LanguageRegistration[]; @@ -47,7 +40,6 @@ export interface ShikiConfig { } export interface AstroMarkdownOptions { - drafts?: boolean; syntaxHighlight?: 'shiki' | 'prism' | false; shikiConfig?: ShikiConfig; remarkPlugins?: RemarkPlugins; |