mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-29 13:47:02 +08:00
fix: should support object.type === 'code'
This commit is contained in:
parent
304305fe08
commit
3bccc9197b
@ -1,7 +1,8 @@
|
||||
import React from 'react';
|
||||
import hljs from 'highlight.js';
|
||||
|
||||
export function objectToComponent(object, index) {
|
||||
if (object === null) return; // TODO: mark-twain support table
|
||||
if (object === null) return;
|
||||
|
||||
const children = object.children;
|
||||
|
||||
@ -12,6 +13,18 @@ export function objectToComponent(object, index) {
|
||||
});
|
||||
}
|
||||
|
||||
if (object.type === 'code') {
|
||||
const highlightedCode = hljs.highlight('javascript', children).value;
|
||||
return (
|
||||
<div className="highlight" key={index}>
|
||||
<pre>
|
||||
<code className={object.props.lang}
|
||||
dangerouslySetInnerHTML={{ __html: highlightedCode }} />
|
||||
</pre>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof children === 'string') {
|
||||
return React.createElement(object.type, {
|
||||
key: index,
|
||||
@ -19,7 +32,7 @@ export function objectToComponent(object, index) {
|
||||
});
|
||||
}
|
||||
return React.createElement(
|
||||
object.type, { key: Math.random() },
|
||||
object.type, { key: index },
|
||||
children && children.map(objectToComponent) // `hr` has no children
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user