Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated markdown-remark APIs #9182

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shiny-trees-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/markdown-remark': major
---

Removes deprecated APIs. All Astro packages had been refactored to not use these APIs.
16 changes: 0 additions & 16 deletions packages/markdown/remark/src/frontmatter-injection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
};
}
39 changes: 1 addition & 38 deletions packages/markdown/remark/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import type {
AstroMarkdownOptions,
MarkdownProcessor,
MarkdownRenderingOptions,
MarkdownRenderingResult,
MarkdownVFile,
} from './types.js';
import type { AstroMarkdownOptions, MarkdownProcessor, MarkdownVFile } from './types.js';

import {
InvalidAstroDataError,
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions packages/markdown/remark/src/internal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
export {
InvalidAstroDataError,
safelyGetAstroData,
toRemarkInitializeAstroData,
} from './frontmatter-injection.js';
export { InvalidAstroDataError, safelyGetAstroData } from './frontmatter-injection.js';
Loading