Open samuelgoldenbaum opened 3 years ago
also looking for this function. Were you manage to implement this? @samuelgoldenbaum
Here is a partial solution if it can help :
const totalLines = codeString.length;
const maxDigits = totalLines.toString().length;
const formattedCodeString = codeString.map((line, index) => {
const lineNumber = (index + 1).toString().padStart(maxDigits, ' ');
return `${lineNumber} | ${line}`;
}).join('\n');
This version actually support showLineNumber, also there is some problems about the format of linenumber. Here is my solution temporarily.
function createNativeElement({ node, stylesheet, key, defaultColor, fontFamily, fontSize = 12 }) { const { properties, type, tagName: TagName, value } = node; const startingStyle = { fontFamily, fontSize, height: fontSize + 15, paddingRight: 30 };
if (type === 'text') { return ( <Text key={key} style={Object.assign({ color: defaultColor }, startingStyle)}
{value} ); } else if (TagName) { const childrenCreator = createChildren({ stylesheet, fontSize, fontFamily }); const style = createStyleObject( properties.className, Object.assign( { color: defaultColor }, properties.style, startingStyle ), stylesheet ); const children = childrenCreator(node.children, style.color || defaultColor); if (properties.className.indexOf("linenumber") != -1) { return <><Text key={key} style={[style, {}]}>{children}
</> } if (properties.className.length) { return children } return {children} ; } }
Before I go down the rabbit hole of trying to implement line numbers, is there a reason they were not implemented—anything I need to be aware of?