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 | |
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')
-rw-r--r-- | packages/markdown/remark/CHANGELOG.md | 2 | ||||
-rw-r--r-- | packages/markdown/remark/package.json | 27 | ||||
-rw-r--r-- | packages/markdown/remark/src/index.ts | 18 |
3 files changed, 22 insertions, 25 deletions
diff --git a/packages/markdown/remark/CHANGELOG.md b/packages/markdown/remark/CHANGELOG.md index 701e045ab..d92ce6782 100644 --- a/packages/markdown/remark/CHANGELOG.md +++ b/packages/markdown/remark/CHANGELOG.md @@ -1,4 +1,4 @@ -# @astrojs/markdown-support +# @astrojs/markdown-remark ## 0.4.0 diff --git a/packages/markdown/remark/package.json b/packages/markdown/remark/package.json index 22522bea3..384537881 100644 --- a/packages/markdown/remark/package.json +++ b/packages/markdown/remark/package.json @@ -19,25 +19,24 @@ }, "dependencies": { "@astrojs/prism": "^0.3.0", - "@silvenon/remark-smartypants": "^1.0.0", "assert": "^2.0.0", - "github-slugger": "^1.3.0", + "github-slugger": "^1.4.0", "gray-matter": "^4.0.3", "mdast-util-mdx-expression": "^1.1.1", - "mdast-util-mdx-jsx": "^1.1.1", - "micromark-extension-mdx-expression": "^1.0.0", - "micromark-extension-mdx-jsx": "^1.0.0", + "mdast-util-mdx-jsx": "^1.1.3", + "micromark-extension-mdx-expression": "^1.0.3", + "micromark-extension-mdx-jsx": "^1.0.2", "prismjs": "^1.25.0", - "rehype-raw": "^6.0.0", - "rehype-stringify": "^9.0.1", - "remark-footnotes": "^4.0.1", - "remark-gfm": "^2.0.0", - "remark-parse": "^10.0.0", - "remark-rehype": "^9.0.0", - "remark-slug": "^7.0.0", - "unified": "^10.1.0", + "rehype-raw": "^6.1.0", + "rehype-slug": "^5.0.0", + "rehype-stringify": "^9.0.2", + "remark-gfm": "^3.0.1", + "remark-parse": "^10.0.1", + "remark-rehype": "^10.0.1", + "remark-smartypants": "^2.0.0", + "unified": "^10.1.1", "unist-util-map": "^3.0.0", - "unist-util-visit": "^4.0.0" + "unist-util-visit": "^4.1.0" }, "devDependencies": { "@types/github-slugger": "^1.3.0", 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)); |