diff options
| author | Nozomu Kaneko <nozom.kaneko@gmail.com> | 2012-12-19 06:13:20 +0900 |
|---|---|---|
| committer | Nozomu Kaneko <nozom.kaneko@gmail.com> | 2012-12-19 06:13:20 +0900 |
| commit | ff487e7a5b7de61ed57d7043750aed3bedd611eb (patch) | |
| tree | df4b44043ada24fa38a35b79bee088ed6e66bb3b | |
| parent | e1bf8968511b3d6c2459d1f0e2abd306b8f55f27 (diff) | |
| download | sphinx-ff487e7a5b7de61ed57d7043750aed3bedd611eb.tar.gz | |
fix #1058 Footnote backlinks do not work
| -rw-r--r-- | sphinx/environment.py | 3 | ||||
| -rw-r--r-- | tests/root/contents.txt | 1 | ||||
| -rw-r--r-- | tests/root/footnote.txt | 40 | ||||
| -rw-r--r-- | tests/test_footnote.py | 37 |
4 files changed, 80 insertions, 1 deletions
diff --git a/sphinx/environment.py b/sphinx/environment.py index 0b9e5bcc..36ab36d4 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -183,7 +183,8 @@ class CitationReferences(Transform): for citnode in self.document.traverse(nodes.citation_reference): cittext = citnode.astext() refnode = addnodes.pending_xref(cittext, reftype='citation', - reftarget=cittext, refwarn=True) + reftarget=cittext, refwarn=True, + ids=citnode["ids"]) refnode.line = citnode.line or citnode.parent.line refnode += nodes.Text('[' + cittext + ']') citnode.parent.replace(citnode, refnode) diff --git a/tests/root/contents.txt b/tests/root/contents.txt index 0a8ca00e..67384351 100644 --- a/tests/root/contents.txt +++ b/tests/root/contents.txt @@ -28,6 +28,7 @@ Contents: extensions versioning/index only + footnote i18n/index Python <http://python.org/> diff --git a/tests/root/footnote.txt b/tests/root/footnote.txt new file mode 100644 index 00000000..c1359dfe --- /dev/null +++ b/tests/root/footnote.txt @@ -0,0 +1,40 @@ +:tocdepth: 2 + +Testing footnote and citation +================================ +.. #1058 footnote-backlinks-do-not-work + +numbered footnote +-------------------- + +[1]_ + +auto-numbered footnote +------------------------------ + +[#]_ + +named footnote +-------------------- + +[#foo]_ + +citation +-------------------- + +[bar]_ + +footenotes +-------------------- + +.. rubric:: Footnotes + +.. [1] numbered + +.. [#] auto numbered + +.. [#foo] named + +.. rubric:: Citations + +.. [bar] cite diff --git a/tests/test_footnote.py b/tests/test_footnote.py new file mode 100644 index 00000000..3a3d5967 --- /dev/null +++ b/tests/test_footnote.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +""" + test_footnote + ~~~~~~~~~~~~~ + + Test for footnote and citation. + + :copyright: Copyright 2010 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from util import * + + +def teardown_module(): + (test_root / '_build').rmtree(True) + + +@with_app(buildername='html') +def test_html(app): + app.builder.build(['footnote']) + result = (app.outdir / 'footnote.html').text(encoding='utf-8') + expects = [ + '<a class="footnote-reference" href="#id5" id="id1">[1]</a>', + '<a class="footnote-reference" href="#id6" id="id2">[2]</a>', + '<a class="footnote-reference" href="#foo" id="id3">[3]</a>', + '<a class="reference internal" href="#bar" id="id4">[bar]</a>', + '<a class="fn-backref" href="#id1">[1]</a>', + '<a class="fn-backref" href="#id2">[2]</a>', + '<a class="fn-backref" href="#id3">[3]</a>', + '<a class="fn-backref" href="#id4">[bar]</a>', + ] + for expect in expects: + matches = re.findall(re.escape(expect), result) + assert len(matches) == 1 |
