Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for passing options to remark-rehype #669

Merged
merged 6 commits into from Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/react-markdown.js
Expand Up @@ -13,6 +13,7 @@
* @property {PluggableList} [plugins=[]] **deprecated**: use `remarkPlugins` instead
* @property {PluggableList} [remarkPlugins=[]]
* @property {PluggableList} [rehypePlugins=[]]
* @property {import('remark-rehype').Options} [rehypeOptions={}]
peolic marked this conversation as resolved.
Show resolved Hide resolved
*
* @typedef LayoutOptions
* @property {string} [className]
Expand Down Expand Up @@ -87,7 +88,10 @@ export function ReactMarkdown(options) {
.use(remarkParse)
// TODO: deprecate `plugins` in v8.0.0.
.use(options.remarkPlugins || options.plugins || [])
.use(remarkRehype, {allowDangerousHtml: true})
.use(remarkRehype, {
...options.rehypeOptions,
allowDangerousHtml: true
})
.use(options.rehypePlugins || [])
.use(rehypeFilter, options)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -87,7 +87,7 @@
"property-information": "^6.0.0",
"react-is": "^17.0.0",
"remark-parse": "^10.0.0",
"remark-rehype": "^9.0.0",
"remark-rehype": "^10.0.0",
"space-separated-tokens": "^2.0.0",
"style-to-object": "^0.3.0",
"unified": "^10.0.0",
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Expand Up @@ -175,6 +175,8 @@ The default export is `ReactMarkdown`.
list of [remark plugins][remark-plugins] to use
* `rehypePlugins` (`Array<Plugin>`, default: `[]`)\
list of [rehype plugins][rehype-plugins] to use
* `rehypeOptions` ([`RemarkRehype.Options`][remark-rehype-options], default: `{}`)\
options to pass through to [remark-rehype][]
wooorm marked this conversation as resolved.
Show resolved Hide resolved
* `className` (`string?`)\
wrap the markdown in a `div` with this class name
* `skipHtml` (`boolean`, default: `false`)\
Expand Down Expand Up @@ -733,6 +735,10 @@ abide by its terms.

[rehype-plugins]: https://github.com/rehypejs/rehype/blob/main/doc/plugins.md#list-of-plugins

[remark-rehype]: https://github.com/remarkjs/remark-rehype

[remark-rehype-options]: https://github.com/remarkjs/remark-rehype#options

wooorm marked this conversation as resolved.
Show resolved Hide resolved
[awesome-remark]: https://github.com/remarkjs/awesome-remark

[awesome-rehype]: https://github.com/rehypejs/awesome-rehype
Expand Down
19 changes: 19 additions & 0 deletions test/test.jsx
Expand Up @@ -874,6 +874,25 @@ test('should render image references', () => {
)
})

test('should render footnote with custom options', () => {
const input = [
'This is a statement[^1] with a citation.',
'',
'[^1]: This is a footnote for the citation.'
].join('\n')

assert.equal(
asHtml(
<Markdown
children={input}
remarkPlugins={[gfm]}
rehypeOptions={{clobberPrefix: 'user-content-'}}
peolic marked this conversation as resolved.
Show resolved Hide resolved
/>
),
'<p>This is a statement<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="true" aria-describedby="footnote-label">1</a></sup> with a citation.</p>\n<section data-footnotes="true" class="footnotes"><h2 id="footnote-label" class="sr-only">Footnotes</h2>\n<ol>\n<li id="user-content-fn-1">\n<p>This is a footnote for the citation. <a href="#user-content-fnref-1" data-footnote-backref="true" class="data-footnote-backref" aria-label="Back to content">↩</a></p>\n</li>\n</ol>\n</section>'
)
})

test('should support definitions with funky keys', () => {
const input =
'[][__proto__] and [][constructor]\n\n[__proto__]: a\n[constructor]: b'
Expand Down