Skip to content

Commit

Permalink
Remove support for className prop
Browse files Browse the repository at this point in the history
Closes GH-781.
Closes GH-799.

Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>

Co-authored-by: Remco Haszing <remcohaszing@gmail.com>
  • Loading branch information
wooorm and remcohaszing committed Feb 20, 2025
1 parent 747e505 commit aaaa40b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 42 deletions.
16 changes: 2 additions & 14 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @import {Element, ElementContent, Nodes, Parents, Root} from 'hast'
* @import {Element, Nodes, Parents, Root} from 'hast'
* @import {Root as MdastRoot} from 'mdast'
* @import {ComponentProps, ElementType, ReactElement} from 'react'
* @import {Options as RemarkRehypeOptions} from 'remark-rehype'
Expand Down Expand Up @@ -127,6 +127,7 @@ const deprecations = [
id: 'replace-allownode-allowedtypes-and-disallowedtypes',
to: 'allowedElements'
},
{from: 'className', id: 'deprecate-classname'},
{
from: 'disallowedTypes',
id: 'replace-allownode-allowedtypes-and-disallowedtypes',
Expand Down Expand Up @@ -322,19 +323,6 @@ function post(tree, options) {
)
}

// Wrap in `div` if there’s a class name.
if (options.className) {
tree = {
type: 'element',
tagName: 'div',
properties: {className: options.className},
// Assume no doctypes.
children: /** @type {Array<ElementContent>} */ (
tree.type === 'root' ? tree.children : [tree]
)
}
}

visit(tree, transform)

return toJsxRuntime(tree, {
Expand Down
2 changes: 0 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,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<string>`, default: `[]`)
Expand Down
26 changes: 0 additions & 26 deletions test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,32 +70,6 @@ test('Markdown', async function (t) {
}, /Unexpected `allowDangerousHtml` prop, remove it/)
})

await t.test('should support `className`', function () {
assert.equal(
renderToStaticMarkup(<Markdown children="a" className="md" />),
'<div class="md"><p>a</p></div>'
)
})

await t.test('should support `className` (if w/o root)', function () {
assert.equal(
renderToStaticMarkup(
<Markdown children={'a'} className="b" rehypePlugins={[plugin]} />
),
'<div class="b"></div>'
)

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(
renderToStaticMarkup(<Markdown children="> a" />),
Expand Down

0 comments on commit aaaa40b

Please sign in to comment.