summaryrefslogtreecommitdiff
path: root/doc/sphinxext/numpydoc.py
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2009-04-19 16:18:45 +0000
committerPauli Virtanen <pav@iki.fi>2009-04-19 16:18:45 +0000
commit0d18cd71f1be611a3a5c5cf0fe4ce2a7aa076188 (patch)
tree0cca2794e9e5dfb81ba594c2e7b8764f8ac87dfe /doc/sphinxext/numpydoc.py
parente427f7a166b83e6523248eaddabd0742f9d329e9 (diff)
downloadnumpy-0d18cd71f1be611a3a5c5cf0fe4ce2a7aa076188.tar.gz
sphinxext: use real RST references for bibliographies, and add suitable links for Latex
Diffstat (limited to 'doc/sphinxext/numpydoc.py')
-rw-r--r--doc/sphinxext/numpydoc.py33
1 files changed, 17 insertions, 16 deletions
diff --git a/doc/sphinxext/numpydoc.py b/doc/sphinxext/numpydoc.py
index 926667dc0..edd58597f 100644
--- a/doc/sphinxext/numpydoc.py
+++ b/doc/sphinxext/numpydoc.py
@@ -22,6 +22,7 @@ import inspect
def mangle_docstrings(app, what, name, obj, options, lines,
reference_offset=[0]):
+
if what == 'module':
# Strip top title
title_re = re.compile(r'^\s*[#*=]{4,}\n[a-z0-9 -]+\n[#*=]{4,}\s*',
@@ -43,25 +44,25 @@ def mangle_docstrings(app, what, name, obj, options, lines,
# replace reference numbers so that there are no duplicates
references = []
- for l in lines:
- l = l.strip()
- if l.startswith('.. ['):
- try:
- references.append(int(l[len('.. ['):l.index(']')]))
- except ValueError:
- print "WARNING: invalid reference in %s docstring" % name
-
- # Start renaming from the biggest number, otherwise we may
- # overwrite references.
- references.sort()
+ for line in lines:
+ line = line.strip()
+ m = re.match(r'^.. \[([a-z0-9_.-])\]', line, re.I)
+ if m:
+ references.append(m.group(1))
+
+ # start renaming from the longest string, to avoid overwriting parts
+ references.sort(key=lambda x: -len(x))
if references:
for i, line in enumerate(lines):
for r in references:
- new_r = reference_offset[0] + r
- lines[i] = lines[i].replace('[%d]_' % r,
- '[%d]_' % new_r)
- lines[i] = lines[i].replace('.. [%d]' % r,
- '.. [%d]' % new_r)
+ if re.match(r'^\d+$', r):
+ new_r = "R%d" % (reference_offset[0] + int(r))
+ else:
+ new_r = "%s%d" % (r, reference_offset[0])
+ lines[i] = lines[i].replace('[%s]_' % r,
+ '[%s]_' % new_r)
+ lines[i] = lines[i].replace('.. [%s]' % r,
+ '.. [%s]' % new_r)
reference_offset[0] += len(references)