diff options
author | 2021-11-22 17:48:00 -0300 | |
---|---|---|
committer | 2021-11-22 14:48:00 -0600 | |
commit | 679d4395ec068f056a8278db17e4a4852eece222 (patch) | |
tree | fa4df0eb155f128cffda67e56ef5f7b473e3c6d8 /packages/markdown/remark/src | |
parent | ce8f8e06c0d79fbe44538a1d63c5bf3a79ba27ff (diff) | |
download | astro-679d4395ec068f056a8278db17e4a4852eece222.tar.gz astro-679d4395ec068f056a8278db17e4a4852eece222.tar.zst astro-679d4395ec068f056a8278db17e4a4852eece222.zip |
Markdown package improvements (#1954)
* Re-add smartypants
* Updated packages
* Remove all the default plugins if there are either remark or rehype plugins
* Replace deperecated remark-slug with rehype-slug
* Added MarkdownParserResponse type
* Update documentation
* Removed type import from markdown package
* Updated remark-smartypants
* Changelog
* Missed one change
* Split changelogs
* Upgraded some MDX dependencies
* Fix typos in documentation
* Changed CHANGELOG.md package name
* Renamed smartypants
Diffstat (limited to 'packages/markdown/remark/src')
-rw-r--r-- | packages/markdown/remark/src/index.ts | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts index 8ea5263b8..88033db14 100644 --- a/packages/markdown/remark/src/index.ts +++ b/packages/markdown/remark/src/index.ts @@ -28,20 +28,13 @@ export async function renderMarkdownWithFrontmatter(contents: string, opts?: Mar return { ...value, frontmatter }; } -export const DEFAULT_REMARK_PLUGINS = [ - 'remark-gfm', - 'remark-footnotes', - // TODO: reenable smartypants! - // '@silvenon/remark-smartypants' -]; +export const DEFAULT_REMARK_PLUGINS = ['remark-gfm', 'remark-smartypants']; -export const DEFAULT_REHYPE_PLUGINS = [ - // empty -]; +export const DEFAULT_REHYPE_PLUGINS = ['rehype-slug']; /** Shared utility for rendering markdown */ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOptions | null) { - const { remarkPlugins = DEFAULT_REMARK_PLUGINS, rehypePlugins = DEFAULT_REHYPE_PLUGINS } = opts ?? {}; + let { remarkPlugins = [], rehypePlugins = [] } = opts ?? {}; const scopedClassName = opts?.$?.scopedClassName; const mode = opts?.mode ?? 'mdx'; const isMDX = mode === 'mdx'; @@ -55,6 +48,11 @@ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOp .use(isMDX ? [remarkExpressions] : []) .use([remarkUnwrap]); + if (remarkPlugins.length === 0 && rehypePlugins.length === 0) { + remarkPlugins = [...DEFAULT_REMARK_PLUGINS]; + rehypePlugins = [...DEFAULT_REHYPE_PLUGINS]; + } + const loadedRemarkPlugins = await Promise.all(loadPlugins(remarkPlugins)); const loadedRehypePlugins = await Promise.all(loadPlugins(rehypePlugins)); |