From 2cf116f80cb5e421ab5cc5eb4a654e7b78c1b8de Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Mon, 1 Apr 2024 22:53:54 +0800 Subject: [PATCH] Remove deprecated APIs from `@astrojs/markdown-remark` (#10629) Co-authored-by: Florian Lefebvre --- .changeset/khaki-otters-return.md | 5 ++++ packages/astro/src/@types/astro.ts | 20 ++++++++++++---- packages/markdown/remark/src/index.ts | 4 +--- packages/markdown/remark/src/remark-prism.ts | 22 ------------------ packages/markdown/remark/src/remark-shiki.ts | 24 -------------------- packages/markdown/remark/src/shiki.ts | 6 +---- packages/markdown/remark/src/types.ts | 23 ------------------- 7 files changed, 23 insertions(+), 81 deletions(-) create mode 100644 .changeset/khaki-otters-return.md delete mode 100644 packages/markdown/remark/src/remark-prism.ts delete mode 100644 packages/markdown/remark/src/remark-shiki.ts diff --git a/.changeset/khaki-otters-return.md b/.changeset/khaki-otters-return.md new file mode 100644 index 000000000000..8d0873fe96be --- /dev/null +++ b/.changeset/khaki-otters-return.md @@ -0,0 +1,5 @@ +--- +"@astrojs/markdown-remark": major +--- + +Removes deprecated APIs including `remarkShiki`, `remarkPrism`, `replaceCssVariables` and several unused types diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index dbf929320af0..df45fa410748 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -2,8 +2,7 @@ import type { OutgoingHttpHeaders } from 'node:http'; import type { AddressInfo } from 'node:net'; import type { MarkdownHeading, - MarkdownMetadata, - MarkdownRenderingResult, + MarkdownVFile, RehypePlugins, RemarkPlugins, RemarkRehype, @@ -45,8 +44,6 @@ export { type AstroIntegrationLogger }; export type { MarkdownHeading, - MarkdownMetadata, - MarkdownRenderingResult, RehypePlugins, RemarkPlugins, ShikiConfig, @@ -2188,6 +2185,21 @@ export interface ManifestData { routes: RouteData[]; } +/** @deprecated Type is no longer used by exported APIs */ +export interface MarkdownMetadata { + headings: MarkdownHeading[]; + source: string; + html: string; +} + +/** @deprecated Type is no longer used by exported APIs */ +export interface MarkdownRenderingResult { + metadata: MarkdownMetadata; + vfile: MarkdownVFile; + code: string; +} + +/** @deprecated Type is no longer used by exported APIs */ export interface MarkdownParserResponse extends MarkdownRenderingResult { frontmatter: MD['frontmatter']; } diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts index ef1afc8fba18..00d6d64ca127 100644 --- a/packages/markdown/remark/src/index.ts +++ b/packages/markdown/remark/src/index.ts @@ -26,9 +26,7 @@ export { rehypeHeadingIds } from './rehype-collect-headings.js'; export { remarkCollectImages } from './remark-collect-images.js'; export { rehypePrism } from './rehype-prism.js'; export { rehypeShiki } from './rehype-shiki.js'; -export { remarkPrism } from './remark-prism.js'; -export { remarkShiki } from './remark-shiki.js'; -export { createShikiHighlighter, replaceCssVariables, type ShikiHighlighter } from './shiki.js'; +export { createShikiHighlighter, type ShikiHighlighter } from './shiki.js'; export * from './types.js'; export const markdownConfigDefaults: Required = { diff --git a/packages/markdown/remark/src/remark-prism.ts b/packages/markdown/remark/src/remark-prism.ts deleted file mode 100644 index 49e38d73cfd7..000000000000 --- a/packages/markdown/remark/src/remark-prism.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { runHighlighterWithAstro } from '@astrojs/prism/dist/highlighter'; -import { visit } from 'unist-util-visit'; -import type { RemarkPlugin } from './types.js'; - -/** - * @deprecated Use `rehypePrism` instead - */ -export function remarkPrism(): ReturnType { - return function (tree: any) { - visit(tree, 'code', (node) => { - let { lang, value } = node; - node.type = 'html'; - - let { html, classLanguage } = runHighlighterWithAstro(lang, value); - let classes = [classLanguage]; - node.value = `
${html}
`; - return node; - }); - }; -} diff --git a/packages/markdown/remark/src/remark-shiki.ts b/packages/markdown/remark/src/remark-shiki.ts deleted file mode 100644 index 512cd453aa38..000000000000 --- a/packages/markdown/remark/src/remark-shiki.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { visit } from 'unist-util-visit'; -import { type ShikiHighlighter, createShikiHighlighter } from './shiki.js'; -import type { RemarkPlugin, ShikiConfig } from './types.js'; - -/** - * @deprecated Use `rehypeShiki` instead - */ -export function remarkShiki(config?: ShikiConfig): ReturnType { - let highlighterAsync: Promise | undefined; - - return async (tree: any) => { - highlighterAsync ??= createShikiHighlighter(config); - const highlighter = await highlighterAsync; - - visit(tree, 'code', (node) => { - const lang = typeof node.lang === 'string' ? node.lang : 'plaintext'; - const html = highlighter.highlight(node.value, lang); - - node.type = 'html'; - node.value = html; - node.children = []; - }); - }; -} diff --git a/packages/markdown/remark/src/shiki.ts b/packages/markdown/remark/src/shiki.ts index c4fef6f7a4f7..f3f9d63bf414 100644 --- a/packages/markdown/remark/src/shiki.ts +++ b/packages/markdown/remark/src/shiki.ts @@ -167,10 +167,6 @@ function normalizePropAsString(value: Properties[string]): string | null { return Array.isArray(value) ? value.join(' ') : (value as string | null); } -/** - * shiki -> shikiji compat as we need to manually replace it - * @internal Exported for error overlay use only - */ -export function replaceCssVariables(str: string) { +function replaceCssVariables(str: string) { return str.replace(COLOR_REPLACEMENT_REGEX, (match) => ASTRO_COLOR_REPLACEMENTS[match] || match); } diff --git a/packages/markdown/remark/src/types.ts b/packages/markdown/remark/src/types.ts index 1fb89316d60e..5861f9e6f9c6 100644 --- a/packages/markdown/remark/src/types.ts +++ b/packages/markdown/remark/src/types.ts @@ -53,13 +53,6 @@ export interface AstroMarkdownOptions { smartypants?: boolean; } -export interface ImageMetadata { - src: string; - width: number; - height: number; - type: string; -} - export interface MarkdownProcessor { render: ( content: string, @@ -83,31 +76,15 @@ export interface MarkdownProcessorRenderResult { }; } -export interface MarkdownRenderingOptions - extends AstroMarkdownOptions, - MarkdownProcessorRenderOptions {} - export interface MarkdownHeading { depth: number; slug: string; text: string; } -export interface MarkdownMetadata { - headings: MarkdownHeading[]; - source: string; - html: string; -} - export interface MarkdownVFile extends VFile { data: { __astroHeadings?: MarkdownHeading[]; imagePaths?: Set; }; } - -export interface MarkdownRenderingResult { - metadata: MarkdownMetadata; - vfile: MarkdownVFile; - code: string; -}