From 6c8fb716e3d6bd27c6206a144bb2192f3252f265 Mon Sep 17 00:00:00 2001 From: peolic <66393006+peolic@users.noreply.github.com> Date: Thu, 13 Jan 2022 12:37:52 +0200 Subject: [PATCH 1/6] Update `remark-rehype` to `^10.0.0` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 67bce621..811d17af 100644 --- a/package.json +++ b/package.json @@ -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", From f34e0fd451d7974a9e7282c791865cf34f29b88f Mon Sep 17 00:00:00 2001 From: peolic <66393006+peolic@users.noreply.github.com> Date: Thu, 13 Jan 2022 12:38:29 +0200 Subject: [PATCH 2/6] Add `remark-rehype` options passthrough --- lib/react-markdown.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/react-markdown.js b/lib/react-markdown.js index 48ba44e3..dc3bac21 100644 --- a/lib/react-markdown.js +++ b/lib/react-markdown.js @@ -13,6 +13,7 @@ * @property {PluggableList} [plugins=[]] **deprecated**: use `remarkPlugins` instead * @property {PluggableList} [remarkPlugins=[]] * @property {PluggableList} [rehypePlugins=[]] + * @property {import('remark-rehype').Options} [rehypeOptions={}] * * @typedef LayoutOptions * @property {string} [className] @@ -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) From d660084038557fbedb7c04e239e456810a5de9d8 Mon Sep 17 00:00:00 2001 From: peolic <66393006+peolic@users.noreply.github.com> Date: Thu, 13 Jan 2022 12:51:41 +0200 Subject: [PATCH 3/6] Update readme --- readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/readme.md b/readme.md index 926e9369..cfc7b1bc 100644 --- a/readme.md +++ b/readme.md @@ -175,6 +175,8 @@ The default export is `ReactMarkdown`. list of [remark plugins][remark-plugins] to use * `rehypePlugins` (`Array`, default: `[]`)\ list of [rehype plugins][rehype-plugins] to use +* `rehypeOptions` ([`RemarkRehype.Options`][remark-rehype-options], default: `{}`)\ + options to pass through to [remark-rehype][] * `className` (`string?`)\ wrap the markdown in a `div` with this class name * `skipHtml` (`boolean`, default: `false`)\ @@ -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 + [awesome-remark]: https://github.com/remarkjs/awesome-remark [awesome-rehype]: https://github.com/rehypejs/awesome-rehype From 3d5cc77a1f75d637b1527425dbc0395446edba01 Mon Sep 17 00:00:00 2001 From: peolic <66393006+peolic@users.noreply.github.com> Date: Thu, 13 Jan 2022 13:19:14 +0200 Subject: [PATCH 4/6] Add test --- test/test.jsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/test.jsx b/test/test.jsx index 384c0aa1..6fdc60b3 100644 --- a/test/test.jsx +++ b/test/test.jsx @@ -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( + + ), + '

This is a statement1 with a citation.

\n

Footnotes

\n
    \n
  1. \n

    This is a footnote for the citation.

    \n
  2. \n
\n
' + ) +}) + test('should support definitions with funky keys', () => { const input = '[][__proto__] and [][constructor]\n\n[__proto__]: a\n[constructor]: b' From d38e591dffa634daa4b2f41e5908b3c9de91956f Mon Sep 17 00:00:00 2001 From: peolic <66393006+peolic@users.noreply.github.com> Date: Fri, 14 Jan 2022 15:41:59 +0200 Subject: [PATCH 5/6] Review - Rename `rehypeOptions` to `remarkRehypeOptions` - Update test --- lib/react-markdown.js | 4 ++-- test/test.jsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/react-markdown.js b/lib/react-markdown.js index dc3bac21..58ef8169 100644 --- a/lib/react-markdown.js +++ b/lib/react-markdown.js @@ -13,7 +13,7 @@ * @property {PluggableList} [plugins=[]] **deprecated**: use `remarkPlugins` instead * @property {PluggableList} [remarkPlugins=[]] * @property {PluggableList} [rehypePlugins=[]] - * @property {import('remark-rehype').Options} [rehypeOptions={}] + * @property {import('remark-rehype').Options} [remarkRehypeOptions={}] * * @typedef LayoutOptions * @property {string} [className] @@ -89,7 +89,7 @@ export function ReactMarkdown(options) { // TODO: deprecate `plugins` in v8.0.0. .use(options.remarkPlugins || options.plugins || []) .use(remarkRehype, { - ...options.rehypeOptions, + ...options.remarkRehypeOptions, allowDangerousHtml: true }) .use(options.rehypePlugins || []) diff --git a/test/test.jsx b/test/test.jsx index 6fdc60b3..2b823a0d 100644 --- a/test/test.jsx +++ b/test/test.jsx @@ -886,10 +886,10 @@ test('should render footnote with custom options', () => { ), - '

This is a statement1 with a citation.

\n

Footnotes

\n
    \n
  1. \n

    This is a footnote for the citation.

    \n
  2. \n
\n
' + '

This is a statement1 with a citation.

\n

Footnotes

\n
    \n
  1. \n

    This is a footnote for the citation.

    \n
  2. \n
\n
' ) }) From 6b9e62029e059f646b877904a011e0950f425462 Mon Sep 17 00:00:00 2001 From: Titus Date: Mon, 17 Jan 2022 18:56:01 +0100 Subject: [PATCH 6/6] Apply suggestions from code review --- readme.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index cfc7b1bc..9cf21150 100644 --- a/readme.md +++ b/readme.md @@ -175,8 +175,8 @@ The default export is `ReactMarkdown`. list of [remark plugins][remark-plugins] to use * `rehypePlugins` (`Array`, default: `[]`)\ list of [rehype plugins][rehype-plugins] to use -* `rehypeOptions` ([`RemarkRehype.Options`][remark-rehype-options], default: `{}`)\ - options to pass through to [remark-rehype][] +* `remarkRehypeOptions` (`Object?`, default: `undefined`)\ + options to pass through to [`remark-rehype`][remark-rehype] * `className` (`string?`)\ wrap the markdown in a `div` with this class name * `skipHtml` (`boolean`, default: `false`)\ @@ -737,8 +737,6 @@ abide by its terms. [remark-rehype]: https://github.com/remarkjs/remark-rehype -[remark-rehype-options]: https://github.com/remarkjs/remark-rehype#options - [awesome-remark]: https://github.com/remarkjs/awesome-remark [awesome-rehype]: https://github.com/rehypejs/awesome-rehype