diff options
Diffstat (limited to 'packages/markdown/remark/src/index.ts')
-rw-r--r-- | packages/markdown/remark/src/index.ts | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts index dd9f95d58..2dfb81d23 100644 --- a/packages/markdown/remark/src/index.ts +++ b/packages/markdown/remark/src/index.ts @@ -1,4 +1,4 @@ -import type { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin } from './types'; +import type { MarkdownRenderingOptions } from './types'; import createCollectHeaders from './rehype-collect-headers.js'; import scopedStyles from './remark-scoped-styles.js'; @@ -18,31 +18,17 @@ import markdown from 'remark-parse'; import markdownToHtml from 'remark-rehype'; import rehypeStringify from 'rehype-stringify'; import rehypeRaw from 'rehype-raw'; -import matter from 'gray-matter'; - -export { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin }; - -/** Internal utility for rendering a full markdown file and extracting Frontmatter data */ -export async function renderMarkdownWithFrontmatter( - contents: string, - opts?: MarkdownRenderingOptions | null -) { - const { data: frontmatter, content } = matter(contents); - const value = await renderMarkdown(content, opts); - return { ...value, frontmatter }; -} + +export * from './types.js'; export const DEFAULT_REMARK_PLUGINS = ['remark-gfm', 'remark-smartypants']; export const DEFAULT_REHYPE_PLUGINS = ['rehype-slug']; /** Shared utility for rendering markdown */ -export async function renderMarkdown(content: string, opts?: MarkdownRenderingOptions | null) { - let { remarkPlugins = [], rehypePlugins = [] } = opts ?? {}; - const scopedClassName = opts?.$?.scopedClassName; - const mode = opts?.mode ?? 'mdx'; - const syntaxHighlight = opts?.syntaxHighlight ?? 'shiki'; - const shikiConfig = opts?.shikiConfig ?? {}; +export async function renderMarkdown(content: string, opts: MarkdownRenderingOptions) { + let { mode, syntaxHighlight, shikiConfig, remarkPlugins, rehypePlugins } = opts; + const scopedClassName = opts.$?.scopedClassName; const isMDX = mode === 'mdx'; const { headers, rehypeCollectHeaders } = createCollectHeaders(); @@ -111,5 +97,3 @@ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOp code: result.toString(), }; } - -export default renderMarkdownWithFrontmatter; |