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

Feature: Right align line numbers #507

Open
Nate-Wilkins opened this issue Jan 24, 2023 · 0 comments
Open

Feature: Right align line numbers #507

Nate-Wilkins opened this issue Jan 24, 2023 · 0 comments

Comments

@Nate-Wilkins
Copy link

Nate-Wilkins commented Jan 24, 2023

I was looking to see if react-syntax-highlighter or prizm.js had the ability to right align the line numbers.

Example

This is the code I currently have:

<SyntaxHighlighter
  children={<>
  # Header
  
  Paragraph and line numbers.
</>}
  style={{ ...coldarkCold }}
  language={"markdown"}
  showLineNumbers
  wrapLongLines
  PreTag="div"
/>

Possible Solutions

  • Align the line numbers to the right by default (there looks to be a style that right aligns the text but this doesn't seem to work on my Chromium version?)
  • Provide a possible option to align them

Workaround

It looks like you can apply grid line styles with the desired effect:

<SyntaxHighlighter
  children={<>
  # Header
  
  Paragraph and line numbers.
</>}
  style={{ ...coldarkCold }}
  lineNumberContainerStyle={{
    display: 'grid',
    gridTemplateColumns: 'repeat(2, 1fr)',
  }}
  lineNumberStyle={{
    gridColumn: '1',
    minWidth: 'unset',
    width: '1.5em',
    textAlign: 'right',
    paddingRight: '0.25em',
  }}
  language={"markdown"}
  showLineNumbers
  wrapLongLines
  PreTag="div"
/>
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

1 participant