Skip to content

Commit 36e4916

Browse files
authored
Add support for passing options to remark-rehype
Closes GH-669. Reviewed-by: Titus Wormer <tituswormer@gmail.com>
1 parent 58806be commit 36e4916

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

lib/react-markdown.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @property {PluggableList} [plugins=[]] **deprecated**: use `remarkPlugins` instead
1414
* @property {PluggableList} [remarkPlugins=[]]
1515
* @property {PluggableList} [rehypePlugins=[]]
16+
* @property {import('remark-rehype').Options} [remarkRehypeOptions={}]
1617
*
1718
* @typedef LayoutOptions
1819
* @property {string} [className]
@@ -87,7 +88,10 @@ export function ReactMarkdown(options) {
8788
.use(remarkParse)
8889
// TODO: deprecate `plugins` in v8.0.0.
8990
.use(options.remarkPlugins || options.plugins || [])
90-
.use(remarkRehype, {allowDangerousHtml: true})
91+
.use(remarkRehype, {
92+
...options.remarkRehypeOptions,
93+
allowDangerousHtml: true
94+
})
9195
.use(options.rehypePlugins || [])
9296
.use(rehypeFilter, options)
9397

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"property-information": "^6.0.0",
8888
"react-is": "^17.0.0",
8989
"remark-parse": "^10.0.0",
90-
"remark-rehype": "^9.0.0",
90+
"remark-rehype": "^10.0.0",
9191
"space-separated-tokens": "^2.0.0",
9292
"style-to-object": "^0.3.0",
9393
"unified": "^10.0.0",

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ The default export is `ReactMarkdown`.
175175
list of [remark plugins][remark-plugins] to use
176176
* `rehypePlugins` (`Array<Plugin>`, default: `[]`)\
177177
list of [rehype plugins][rehype-plugins] to use
178+
* `remarkRehypeOptions` (`Object?`, default: `undefined`)\
179+
options to pass through to [`remark-rehype`][remark-rehype]
178180
* `className` (`string?`)\
179181
wrap the markdown in a `div` with this class name
180182
* `skipHtml` (`boolean`, default: `false`)\
@@ -733,6 +735,8 @@ abide by its terms.
733735

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

738+
[remark-rehype]: https://github.com/remarkjs/remark-rehype
739+
736740
[awesome-remark]: https://github.com/remarkjs/awesome-remark
737741

738742
[awesome-rehype]: https://github.com/rehypejs/awesome-rehype

test/test.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,25 @@ test('should render image references', () => {
874874
)
875875
})
876876

877+
test('should render footnote with custom options', () => {
878+
const input = [
879+
'This is a statement[^1] with a citation.',
880+
'',
881+
'[^1]: This is a footnote for the citation.'
882+
].join('\n')
883+
884+
assert.equal(
885+
asHtml(
886+
<Markdown
887+
children={input}
888+
remarkPlugins={[gfm]}
889+
remarkRehypeOptions={{clobberPrefix: 'main-'}}
890+
/>
891+
),
892+
'<p>This is a statement<sup><a href="#main-fn-1" id="main-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="main-fn-1">\n<p>This is a footnote for the citation. <a href="#main-fnref-1" data-footnote-backref="true" class="data-footnote-backref" aria-label="Back to content">↩</a></p>\n</li>\n</ol>\n</section>'
893+
)
894+
})
895+
877896
test('should support definitions with funky keys', () => {
878897
const input =
879898
'[][__proto__] and [][constructor]\n\n[__proto__]: a\n[constructor]: b'

0 commit comments

Comments
 (0)