Skip to content
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

Closed
ucffool opened this issue Mar 31, 2023 · 6 comments · Fixed by #1437
Closed

New CodeBlock prop: lineNumber #1241

ucffool opened this issue Mar 31, 2023 · 6 comments · Fixed by #1437
Labels
feature request Request a feature or introduce and update to the project.

Comments

@ucffool
Copy link
Contributor

ucffool commented Mar 31, 2023

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:

  • The ability to add line numbers in the code block
  • The ability to customize the starting line number.

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

@ucffool ucffool added the feature request Request a feature or introduce and update to the project. label Mar 31, 2023
@endigo9740
Copy link
Contributor

endigo9740 commented Mar 31, 2023

There's a number of improvements I want for code blocks, including line numbering, row highlighting, etc. But right now
we're limited in some regard to the way Highlight.js syntax highlighting works. It essentially manipulates the markup to add wrapping elements to add color highlighting.

A trivial example would be something like:

Before:

<div>Skeleton</div>

After Highlight.js processing:

<span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Skeleton<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

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.

@bennymi
Copy link
Contributor

bennymi commented Apr 4, 2023

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.

@ucffool
Copy link
Contributor Author

ucffool commented Apr 4, 2023

@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.

@Hi-ImKyle
Copy link

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.

@endigo9740
Copy link
Contributor

@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.

@bennymi
Copy link
Contributor

bennymi commented Apr 25, 2023

@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?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
feature request Request a feature or introduce and update to the project.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants