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

Fix renumbering references in tables #131

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions numpydoc/numpydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ def rename_references(app, what, name, obj, options, lines,
new_r = sixu("R%d") % (reference_offset[0] + int(r))
else:
new_r = sixu("%s%d") % (r, reference_offset[0])
# Attempt to preserve *trailing* whitespace, e.g. in grid table
if len(r) < len(new_r):
# Now longer: Want to remove now redundant trailing whitespace
pad = " " * (len(new_r) - len(r))
lines[i] = lines[i].replace(sixu('[%s]_%s') % (r, pad),
sixu('[%s]_') % new_r)
elif len(new_r) < len(r):
# Now shorter: Must insert extra trailing whitespace
# (but only if there was trailing whitespace)
pad = " " * (len(r) - len(new_r))
lines[i] = lines[i].replace(sixu('[%s]_ ') % r,
sixu('[%s]_%s ') % (new_r, pad))
lines[i] = lines[i].replace(sixu('[%s]_') % r,
sixu('[%s]_') % new_r)
lines[i] = lines[i].replace(sixu('.. [%s]') % r,
Expand Down