From ea2fa564b8fd6d215b57d659f26aff3f5950059c Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Wed, 15 Nov 2023 21:28:17 +0100 Subject: [PATCH 1/4] Deprecate the className prop Users should wrap the `` component inside a `
` manually instead. Closes #781 --- changelog.md | 17 +++++++++++++++++ lib/index.js | 5 +++-- readme.md | 2 -- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index aadd70d..99d126c 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,23 @@ All notable changes will be documented in this file. +## 9.0.1 + +### Deprecate `className` + +The `className` prop was deprecated. +Not only does the `className` prop add the `className` prop, it also implies a +wrapper `
` will be created. +Instead, you should wrap the content in a `
` manually. + +```jsx +
+ + {children} + +
+``` + ## 9.0.0 - 2023-09-27 * [`b67d714`](https://github.com/remarkjs/react-markdown/commit/b67d714) diff --git a/lib/index.js b/lib/index.js index 414a534..61887ab 100644 --- a/lib/index.js +++ b/lib/index.js @@ -116,6 +116,7 @@ const deprecations = [ id: 'replace-allownode-allowedtypes-and-disallowedtypes', to: 'allowedElements' }, + {from: 'className', id: 'deprecate-classname'}, { from: 'disallowedTypes', id: 'replace-allownode-allowedtypes-and-disallowedtypes', @@ -266,8 +267,8 @@ export function Markdown(options) { let remove = allowedElements ? !allowedElements.includes(node.tagName) : disallowedElements - ? disallowedElements.includes(node.tagName) - : false + ? disallowedElements.includes(node.tagName) + : false if (!remove && allowElement && typeof index === 'number') { remove = !allowElement(node, index, parent) diff --git a/readme.md b/readme.md index 65e9983..c3c7c07 100644 --- a/readme.md +++ b/readme.md @@ -256,8 +256,6 @@ Configuration (TypeScript type). cannot combine w/ `disallowedElements` * `children` (`string`, optional) — markdown -* `className` (`string`, optional) - — wrap in a `div` with this class name * `components` ([`Components`][api-components], optional) — map tag names to components * `disallowedElements` (`Array`, default: `[]`) From b2ce3eee9d2d2505b6cafd7c8e9048cf1f2cc165 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Fri, 17 Nov 2023 10:29:00 +0100 Subject: [PATCH 2/4] Remove the className prop entirely --- lib/index.js | 24 +++--------------------- test.jsx | 26 -------------------------- 2 files changed, 3 insertions(+), 47 deletions(-) diff --git a/lib/index.js b/lib/index.js index 61887ab..2646ab0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,7 +4,6 @@ /** * @typedef {import('hast').Element} Element * @typedef {import('hast').ElementContent} ElementContent - * @typedef {import('hast').Nodes} Nodes * @typedef {import('hast').Parents} Parents * @typedef {import('hast').Root} Root * @typedef {import('hast-util-to-jsx-runtime').Components} JsxRuntimeComponents @@ -47,8 +46,6 @@ * cannot combine w/ `disallowedElements`. * @property {string | null | undefined} [children] * Markdown. - * @property {string | null | undefined} [className] - * Wrap in a `div` with this class name. * @property {Components | null | undefined} [components] * Map tag names to components. * @property {ReadonlyArray | null | undefined} [disallowedElements] @@ -150,7 +147,6 @@ export function Markdown(options) { const allowedElements = options.allowedElements const allowElement = options.allowElement const children = options.children || '' - const className = options.className const components = options.components const disallowedElements = options.disallowedElements const rehypePlugins = options.rehypePlugins || emptyPlugins @@ -205,21 +201,7 @@ export function Markdown(options) { } const mdastTree = processor.parse(file) - /** @type {Nodes} */ - let hastTree = processor.runSync(mdastTree, file) - - // Wrap in `div` if there’s a class name. - if (className) { - hastTree = { - type: 'element', - tagName: 'div', - properties: {className}, - // Assume no doctypes. - children: /** @type {Array} */ ( - hastTree.type === 'root' ? hastTree.children : [hastTree] - ) - } - } + const hastTree = processor.runSync(mdastTree, file) visit(hastTree, transform) @@ -267,8 +249,8 @@ export function Markdown(options) { let remove = allowedElements ? !allowedElements.includes(node.tagName) : disallowedElements - ? disallowedElements.includes(node.tagName) - : false + ? disallowedElements.includes(node.tagName) + : false if (!remove && allowElement && typeof index === 'number') { remove = !allowElement(node, index, parent) diff --git a/test.jsx b/test.jsx index f803df9..da526ee 100644 --- a/test.jsx +++ b/test.jsx @@ -61,32 +61,6 @@ test('react-markdown', async function (t) { }, /Unexpected `allowDangerousHtml` prop, remove it/) }) - await t.test('should support `className`', function () { - assert.equal( - asHtml(), - '

a

' - ) - }) - - await t.test('should support `className` (if w/o root)', function () { - assert.equal( - asHtml( - - ), - '
' - ) - - function plugin() { - /** - * @returns {Root} - */ - return function () { - // @ts-expect-error: check how non-roots are handled. - return {type: 'comment', value: 'things!'} - } - } - }) - await t.test('should support a block quote', function () { assert.equal( asHtml(), From 82ae167ec58120cce2aa9611851d6fc5fc4e875e Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Fri, 17 Nov 2023 10:30:01 +0100 Subject: [PATCH 3/4] Remove unused type ElementContent --- lib/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 2646ab0..5e341c8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,7 +3,6 @@ /** * @typedef {import('hast').Element} Element - * @typedef {import('hast').ElementContent} ElementContent * @typedef {import('hast').Parents} Parents * @typedef {import('hast').Root} Root * @typedef {import('hast-util-to-jsx-runtime').Components} JsxRuntimeComponents From 40143b159d9f52b50bfb3607ac888864c5df7d84 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Fri, 17 Nov 2023 11:05:07 +0100 Subject: [PATCH 4/4] Revert changelog changes --- changelog.md | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/changelog.md b/changelog.md index 99d126c..aadd70d 100644 --- a/changelog.md +++ b/changelog.md @@ -2,23 +2,6 @@ All notable changes will be documented in this file. -## 9.0.1 - -### Deprecate `className` - -The `className` prop was deprecated. -Not only does the `className` prop add the `className` prop, it also implies a -wrapper `
` will be created. -Instead, you should wrap the content in a `
` manually. - -```jsx -
- - {children} - -
-``` - ## 9.0.0 - 2023-09-27 * [`b67d714`](https://github.com/remarkjs/react-markdown/commit/b67d714)