Skip to content

Commit

Permalink
feat: pass through stringify options (#963)
Browse files Browse the repository at this point in the history
[![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
  • Loading branch information
kellyjosephprice authored Sep 10, 2024
1 parent 746d83e commit fb4fb7d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lib/mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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));
};
Expand Down

0 comments on commit fb4fb7d

Please sign in to comment.