Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line numbers #30

Open
samuelgoldenbaum opened this issue Oct 5, 2021 · 3 comments
Open

Line numbers #30

samuelgoldenbaum opened this issue Oct 5, 2021 · 3 comments

Comments

@samuelgoldenbaum
Copy link

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?

@Desintegrator
Copy link

also looking for this function. Were you manage to implement this? @samuelgoldenbaum

@rb-x
Copy link

rb-x commented Sep 12, 2023

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');

@gdxie1
Copy link

gdxie1 commented Aug 27, 2024

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};
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants