Skip to content

Commit 746e722

Browse files
authored
fix: array-based className handling (#16)
1 parent 07dae03 commit 746e722

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/mapChildren.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { createElement } from 'react'
33
function mapChild (child, i, depth) {
44
if (child.tagName) {
55
const props = Object.assign({ key: 'lo-' + depth + '-' + i }, child.properties)
6+
7+
if (Array.isArray(props.className)) {
8+
props.className = props.className.join(' ')
9+
}
10+
611
const children = child.children ? child.children.map(mapWithDepth(depth + 1)) : null
712

813
return createElement(child.tagName, props, children)

test/Lowlight.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ describe('react-lowlight', () => {
8686
].join('')
8787
)
8888
})
89+
90+
it('should properly join array-based class names in child elements', () => {
91+
const code = 'function foo() {}'
92+
93+
expect(render({ value: code, language: 'js' }, { withWrapper: true })).toBe(
94+
'<pre class="lowlight"><code class="hljs js"><span class="hljs-keyword">function</span> <span class="hljs-title function_">foo</span>(<span class="hljs-params"></span>) {}</code></pre>'
95+
)
96+
})
8997
})
9098

9199
function render (props, options = {}) {

0 commit comments

Comments
 (0)