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 in code listings #737

Open
DavidBrunow opened this issue Oct 11, 2023 · 3 comments
Open

Line numbers in code listings #737

DavidBrunow opened this issue Oct 11, 2023 · 3 comments
Labels
enhancement Improvements or enhancements to existing functionality

Comments

@DavidBrunow
Copy link

Feature Name

Line numbers in code listings

Description

I'd like the ability to optionally show line numbers in code listings.

Motivation

This would be helpful to me when writing documentation around a code listing in order to explain the code. Being able to say "on line 5" without the reader needing to count to line 5 would allow the documentation to be more clear.

Importance

I don't think this is a super important feature but I do believe that it would improve the user experience for folks reading documentation.

Alternatives Considered

My current workaround is to refer to the symbols in the code listing by name in the documentation surrounding the code listing.

@DavidBrunow DavidBrunow added the enhancement Improvements or enhancements to existing functionality label Oct 11, 2023
@natikgadzhi
Copy link
Contributor

@ethan-kusters that should probably also be in docc-render? I think it's relatively easy to do, too.

@natikgadzhi
Copy link
Contributor

I'm taking a look ;) So the good news is CodeListing can show line numbers.

We just need to figure out how to best tell it to show line numbers, and what level of flexibility we want. If I read the code correctly, it looks for contentNode.showLineNumbers for contentNodes that are codeListing.

So hypothetically, we could do a few things here:

  1. Add an option like @CodeListingsShowLineNumbers(true) or similar. Options are usually scoped to the current page / article, and it feels janky.
  2. See if we can change how we parse the ``` code block syntax to accept something like ``` showLineNumbers, similar to https://rehype-pretty-code.netlify.app/ on a level of a specific code block. That will be more involved, likely require some hacking in swift-markdown, BUT that will allow others to use that, too.
  3. Make site-wide setting and pass it in an env variable or a build flag. That's probably a crappy option because those are obscure, and it will be difficult to document.

I feel like option 2 is what's generally expected with markdown-base documentation systems.

@Anthony-Eid
Copy link
Contributor

Would this be a good second issue for me to take a look at? I'm trying to learn more about this code base and would love to have something to do while I'm waiting on feedback from my pull request.

Admittedly, I'm probably going to need some guidence with attacking this issue, but I'm eager to give it my best shot. 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements or enhancements to existing functionality
Projects
None yet
Development

No branches or pull requests

3 participants