Skip to content

Commit

Permalink
Remove deprecated markdown-remark APIs (#9182)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Nov 27, 2023
1 parent 88f4084 commit c795364
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 59 deletions.
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';

0 comments on commit c795364

Please sign in to comment.