Add line numbers in sphinx.ext.viewdoc#6319
Merged
AA-Turner merged 15 commits intosphinx-doc:masterfrom Jul 28, 2023
Merged
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #6319 +/- ##
==========================================
- Coverage 86.99% 84.18% -2.82%
==========================================
Files 276 274 -2
Lines 52443 39314 -13129
Branches 9208 5835 -3373
==========================================
- Hits 45625 33098 -12527
+ Misses 5163 4900 -263
+ Partials 1655 1316 -339
☔ View full report in Codecov by Sentry. |
tk0miya
requested changes
Apr 25, 2019
| type, start, end = tags[name] | ||
| backlink = urito(pagename, docname) + '#' + refname + '.' + name | ||
| lines[start] = ( | ||
| '<div class="viewcode-block" id="%s"><a class="viewcode-back" ' |
Member
sphinx/ext/viewcode.py
Outdated
| return None | ||
|
|
||
|
|
||
| def split_code_lines(lines): |
Member
There was a problem hiding this comment.
I feel this code is a bit tricky. To be our code robust, we need to make a custom Formatter for pygments. I'll take a look in this weekend.
33d030f to
d99945d
Compare
Member
|
Thanks @benkrikler! A |
This was referenced Jul 28, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Subject: Add an option to the viewcode extension to include line-numbering in the output
Feature or Bugfix
Purpose
I felt that it could help a project I was working on if I the source code as highlighted by the
viewcodeextension could include line numbers. When I looked into the viewcode source, it seemed relatively straightforward to add this, and so as a way to learn a bit about the internals of sphinx I took a go at it.At that point, it seemed like it could be something of use / interest and worth contributing back to the main repository. I'm sorry that this hasn't followed what I believe is the normal approach to adding a feature (I read the Contributing guidelines, and whilst it didn't look like a hard rule, I think I should have opened an issue first)!
Detail
Along the way though, I noticed that, at least in my browser (Firefox 66.0.2) the extra
divinserted around the[docs]link in the highlighted sourcecode output was adding an extra line intermittently (this was with tag v2.0.1 of Sphinx). The div only seems to have served to add a css class, so I have moved that css class to the<a>element instead and removed the encasingdiv. I appreciate that might be a bit drastic (for example, styles might be selecting on thediv), but it did fix the issue. It seems #4701 and #4709 concerned this problem as well, but as far as I could tell the fix as implemented has only partially worked.Relates
<div>in viewcode html output since Sphinx 1.7.0 #4701<div>in viewcode html output #4709