-
-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
New CodeBlock prop: lineNumber #1241
Comments
There's a number of improvements I want for code blocks, including line numbering, row highlighting, etc. But right now A trivial example would be something like: Before:
After Highlight.js processing:
So this concept of "lines" doesn't really exist, as everything gets scrambled a bit. Long story short, some research is needed to see if there's a standardized way to do this. This may, however, involve moving away from Highlight.js in favor of another library that has this functionality build in. Just want to set expectations here for what it'll take to implement something like this. |
A bit of a shameless plug, but @ucffool you might be interested in my SvHighlight library: https://github.com/bennymi/svhighlight It was adapted from Skeleton's CodeBlock component and offers highlighting and some other features. There's no prop for starting line numbers yet but it's something that could be added. |
@bennymi I actually already had that starred! It's actually more than I need for this particular project but thanks for the reminder and shamefree plug. |
Not sure if it's worth looking at but another UI called Mantine for React uses PrismJS for code highlighting, they are able to add the line numbers, though I'm not sure if PrismJS actually supports it out of the box so maybe you can take a peak at how they do it. Here's their page for the Prism component. That being said I like @bennymi's library, just it doesn't really work for me, the lines are super spaced out for no reason from what I can tell so I'd like to ever so slightly push this to a potential final solution. |
@Hi-ImKyle Yep we're aware of Prism. It was in the running alongside Highlight when we created the codeblock component. We just felt Highlight was friendlier since it doesn't require installing various language dependencies. Skeleton is about ease of use, so meshed well with our goals. Doing a quick scan on the Prism docs, none of the examples use line numbers. So this may echo what I said in my previous comment - line numbers are a custom solution on top of the syntax highlighting from these libraries. If you can find documentation for how to enable this via Prism please do share. FYI our code block can potentially support multiple syntax libraries, so again, we will consider Prism if they provide a turnkey solution for this. |
@Hi-ImKyle curious to see what you mean with the lines being too spaced out. If you have a screenshot of it could you open a issue for it on the github page so I can have a look at it? |
Describe what feature you'd like. Pseudo-code, mockups, or screenshots of similar solutions are encouraged!
The default would be
0
(hide).If specified, such as
42
, each line in the code block would be numbered sequentially on the left, starting with the specified value.This is two features in one:
This would be a standout feature, since most implementations of line numbering has no option to adjust the starting number.
What type of pull request would this be?
New Feature
Any links to similar examples or other references we should review?
No response
The text was updated successfully, but these errors were encountered: