Skip to content

Commit

Permalink
fix: map class -> className
Browse files Browse the repository at this point in the history
Fixes #606
  • Loading branch information
quantizor committed Nov 13, 2024
1 parent ada1fad commit 87d8bd3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-waves-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'markdown-to-jsx': patch
---

Handle `class` attribute from arbitrary HTML properly to avoid React warnings.
12 changes: 10 additions & 2 deletions index.compiler.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2460,10 +2460,18 @@ describe('GFM tables', () => {

describe('arbitrary HTML', () => {
it('preserves the HTML given', () => {
render(compiler('<dd>Hello</dd>'))
const ast = compiler('<dd class="foo">Hello</dd>')
expect(ast).toMatchInlineSnapshot(`
<dd
className="foo"
>
Hello
</dd>
`)

render(ast)
expect(root.innerHTML).toMatchInlineSnapshot(`
<dd>
<dd class="foo">
Hello
</dd>
`)
Expand Down
3 changes: 1 addition & 2 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ const ATTRIBUTE_TO_JSX_PROP_MAP = [
'cellPadding',
'cellSpacing',
'charSet',
'className',
'classId',
'colSpan',
'contentEditable',
Expand Down Expand Up @@ -126,7 +125,7 @@ const ATTRIBUTE_TO_JSX_PROP_MAP = [
obj[x.toLowerCase()] = x
return obj
},
{ for: 'htmlFor' }
{ class: 'className', for: 'htmlFor' }
)

const namedCodesToUnicode = {
Expand Down

0 comments on commit 87d8bd3

Please sign in to comment.