0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-10 23:01:26 -05:00

Remove deprecated APIs from @astrojs/markdown-remark (#10629)

Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
This commit is contained in:
Bjorn Lu 2024-04-01 22:53:54 +08:00 committed by GitHub
parent 374efcdff9
commit 2cf116f80c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 23 additions and 81 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/markdown-remark": major
---
Removes deprecated APIs including `remarkShiki`, `remarkPrism`, `replaceCssVariables` and several unused types

View file

@ -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'];
}

View file

@ -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<AstroMarkdownOptions> = {

View file

@ -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<RemarkPlugin> {
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 = `<pre class="${classes.join(
' '
)}"><code is:raw class="${classLanguage}">${html}</code></pre>`;
return node;
});
};
}

View file

@ -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<RemarkPlugin> {
let highlighterAsync: Promise<ShikiHighlighter> | 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 = [];
});
};
}

View file

@ -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);
}

View file

@ -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<string>;
};
}
export interface MarkdownRenderingResult {
metadata: MarkdownMetadata;
vfile: MarkdownVFile;
code: string;
}