Display line numbers when viewing source code
See original GitHub issueProblem Description
Two related enhancement proposals:
- Are there any chances to (optionally) display source code line numbers in html documentation?
- Are there any chances to link to specific source code line numbers in html documentation?
Proposal
- When you click
view-source
at the right side of a function definition (or Class, or whatever), source code lines are shown. Is it possible that these lines come with the line number shown on the left side? (as an option, like many text editors offer) - I noticed that each line of source code is rendered as a single
<span class="sd">source code</span>
If eachspan
is preceded with a<a name="lnXXXX">
tag, then that line (number XXXX) would be linkable using module.html#lnXXXX
Alternatives
- For showing line numbers:
- Offer this as an option in
pdoc.render.configure(show_line_numbers: bool)
- Offer this as a clickable option in html output, next to
view-source
on the right side - Offer both options
- For introducing linking anchors:
- Offer this as an option in
pdoc.render.configure(create_line_anchors: bool)
Probably this would imply thatview-source
should be active by default in rendered html output as well, not needing to click anywhere (otherwise, module.html#lnXXXX links to specific span tag anchors won’t do anything if those span tags are not already visible whenmodule.html
is loaded).
Additional context
https://pdoc.dev/docs/pdoc/render.html#configure https://pdoc.dev/docs/pdoc/doc.html#Doc.source_lines Useful to complement use case described in #325 and specially in #327
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
html: How to add line numbers to a source code block
Without using float , there is a simple solution so text isn't wrapped under the line numbers. The trick is setting a margin...
Read more >Display line numbers for code - Visual Studio (Windows)
You can show or hide line numbers in your code. Here's how. On the menu bar, choose Tools > Options. Expand the Text...
Read more >visualstudio-docs/how-to-display-line-numbers-in-the-editor ...
You can show or hide line numbers in your code. Here's how. On the menu bar, choose Tools > Options. Expand the Text...
Read more >Firefox: Find Line Numbers in View Source
To find line numbers: From the Firefox menu, select View > Page Source. Firefox opens the page source in a new window. Type...
Read more >Source code line numbers and JavaScript - All this - Dr. Drang
The purpose of “toggleLN” is to go through the <code> element associated with the clicked button and turn off the display of all...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think line numbers should be generally useful for everyone, no need to make it an option. There are line numbers on GitHub as well and you cannot configure it. 😃
I’ve implemented the necessary changes in https://github.com/mitmproxy/pdoc/compare/main...mhils:linenumbers, but we first need to wait for a pygments fix to ship in https://github.com/pygments/pygments/pull/2026.
I’m afraid you got me wrong. I wasn’t trying to force any pdoc changes with my comments in #343 I only wanted to share the solution I had found for my problem (originally stated above in this issue). So other newbies like me could find it useful. Please acept my apologies, it wasn’t necesary to answer me any further or locking conversation (there were no pending questions, actually).
Sorry again