-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add line numbers in sphinx.ext.viewdoc
#6319
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. |
for name, docname in used.items(): | ||
type, start, end = tags[name] | ||
backlink = urito(pagename, docname) + '#' + refname + '.' + name | ||
lines[start] = ( | ||
'<div class="viewcode-block" id="%s"><a class="viewcode-back" ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sphinx/ext/viewcode.py
Outdated
@@ -141,6 +141,23 @@ def missing_reference(app, env, node, contnode): | |||
return None | |||
|
|||
|
|||
def split_code_lines(lines): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Thanks @benkrikler! A |
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
viewcode
extension 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
div
inserted 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