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

Deprecate the className prop #799

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,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
Expand Down Expand Up @@ -47,8 +45,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<string> | null | undefined} [disallowedElements]
Expand Down Expand Up @@ -116,6 +112,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 @@ -149,7 +146,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
Expand Down Expand Up @@ -204,21 +200,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<ElementContent>} */ (
hastTree.type === 'root' ? hastTree.children : [hastTree]
)
}
}
const hastTree = processor.runSync(mdastTree, file)

visit(hastTree, transform)

Expand Down
2 changes: 0 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>`, default: `[]`)
Expand Down
26 changes: 0 additions & 26 deletions test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<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(
asHtml(
<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(
asHtml(<Markdown children="> a" />),
Expand Down