0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Remove deprecated markdown-remark APIs (#9182)

This commit is contained in:
Bjorn Lu 2023-11-28 00:32:39 +08:00 committed by GitHub
parent 88f40846d4
commit c7953645ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 59 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/markdown-remark': major
---
Removes deprecated APIs. All Astro packages had been refactored to not use these APIs.

View file

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

View file

@ -1,10 +1,4 @@
import type {
AstroMarkdownOptions,
MarkdownProcessor,
MarkdownRenderingOptions,
MarkdownRenderingResult,
MarkdownVFile,
} from './types.js';
import type { AstroMarkdownOptions, MarkdownProcessor, MarkdownVFile } from './types.js';
import {
InvalidAstroDataError,
@ -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) {

View file

@ -1,5 +1 @@
export {
InvalidAstroDataError,
safelyGetAstroData,
toRemarkInitializeAstroData,
} from './frontmatter-injection.js';
export { InvalidAstroDataError, safelyGetAstroData } from './frontmatter-injection.js';