From fb4fb7db1998463c9cf43764d533c14383e63a9f Mon Sep 17 00:00:00 2001 From: Kelly Joseph Price Date: Tue, 10 Sep 2024 10:35:03 -0700 Subject: [PATCH] feat: pass through stringify options (#963) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![PR App][icn]][demo] | RM-10779 :-------------------:|:----------: ## 🧰 Changes Allows passing through options to `remark-stringify`. There are places in the main app where we'd like to be able control the formatting of mdx. ## 🧬 QA & Testing - [Broken on production][prod]. - [Working in this PR app][demo]. [demo]: https://markdown-pr-PR_NUMBER.herokuapp.com [prod]: https://SUBDOMAIN.readme.io [icn]: https://user-images.githubusercontent.com/886627/160426047-1bee9488-305a-4145-bb2b-09d8b757d38a.svg --- README.md | 8 ++++++++ lib/mdx.ts | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 42b25d269..234612387 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,14 @@ A module ([`RMDXModule`](#rmdxmodule)) of renderable components Compiles an ast to mdx. +###### Parameters + +Extends [`remark-stringify` options](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options). + +###### Returns + +An mdx string. + #### `mdast` Parses mdx to an mdast. diff --git a/lib/mdx.ts b/lib/mdx.ts index e1935d707..9732dc143 100644 --- a/lib/mdx.ts +++ b/lib/mdx.ts @@ -7,7 +7,7 @@ import remarkStringify from 'remark-stringify'; import compilers from '../processor/compile'; import { divTransformer, readmeToMdx, tablesToJsx } from '../processor/transform'; -export const mdx = (tree: any, { hast = false } = {}) => { +export const mdx = (tree: any, { hast = false, ...opts } = {}) => { const processor = unified() .use(hast ? rehypeRemark : undefined) .use(remarkMdx) @@ -16,7 +16,7 @@ export const mdx = (tree: any, { hast = false } = {}) => { .use(readmeToMdx) .use(tablesToJsx) .use(compilers) - .use(remarkStringify); + .use(remarkStringify, opts); return processor.stringify(processor.runSync(tree)); };