add test.jsx
This commit is contained in:
parent
b35f661ffb
commit
7e4fb473f5
41
test.jsx
Normal file
41
test.jsx
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
function createStyleObject(classNames, style) {
|
||||||
|
return classNames.reduce((styleObject, className) => {
|
||||||
|
return {...styleObject, ...style[className]};
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
function createClassNameString(classNames) {
|
||||||
|
return classNames.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
// this comment is here to demonstrate an extremely long line length, well beyond what you should probably allow in your own code, though sometimes you'll be highlighting code you can't refactor, which is unfortunate but should be handled gracefully
|
||||||
|
|
||||||
|
function createChildren(style, useInlineStyles) {
|
||||||
|
let childrenCount = 0;
|
||||||
|
return children => {
|
||||||
|
childrenCount += 1;
|
||||||
|
return children.map((child, i) => createElement({
|
||||||
|
node: child,
|
||||||
|
style,
|
||||||
|
useInlineStyles,
|
||||||
|
key:`code-segment-${childrenCount}-${i}`
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createElement({ node, style, useInlineStyles, key }) {
|
||||||
|
const { properties, type, tagName, value } = node;
|
||||||
|
if (type === "text") {
|
||||||
|
return value;
|
||||||
|
} else if (tagName) {
|
||||||
|
const TagName = tagName;
|
||||||
|
const childrenCreator = createChildren(style, useInlineStyles);
|
||||||
|
const props = (
|
||||||
|
useInlineStyles
|
||||||
|
? { style: createStyleObject(properties.className, style) }
|
||||||
|
: { className: createClassNameString(properties.className) }
|
||||||
|
);
|
||||||
|
const children = childrenCreator(node.children);
|
||||||
|
return <TagName key={key} {...props}>{children}</TagName>;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user