summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2017-06-04 13:54:40 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2017-06-04 13:55:14 +0900
commit2f61be8bb7137d0f2f712b8b230d7ab93d003b6f (patch)
treec448058890b25fd2ee208b1de7326eda53d1c790
parente3c39deb1e4ce9ea95066c72f79bc7251a0f68a2 (diff)
downloadsphinx-git-2f61be8bb7137d0f2f712b8b230d7ab93d003b6f.tar.gz
Fix Emit wrong warnings if citation label includes hyphens (refs: #3558)
-rw-r--r--CHANGES1
-rw-r--r--sphinx/domains/std.py9
-rw-r--r--tests/roots/test-root/footnote.txt3
-rw-r--r--tests/test_build_html.py16
-rw-r--r--tests/test_build_html5.py16
5 files changed, 28 insertions, 17 deletions
diff --git a/CHANGES b/CHANGES
index 5db4fc395..f84a70c4c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -19,6 +19,7 @@ Bugs fixed
* #3821: Failed to import sphinx.util.compat with docutils-0.14rc1
* #3829: sphinx-quickstart template is incomplete regarding use of alabaster
* #3772: 'str object' has no attribute 'filename'
+* Emit wrong warnings if citation label includes hyphens (refs: #3558)
Testing
--------
diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py
index a7a41747e..26645eed2 100644
--- a/sphinx/domains/std.py
+++ b/sphinx/domains/std.py
@@ -493,7 +493,7 @@ class StandardDomain(Domain):
'progoptions': {}, # (program, name) -> docname, labelid
'objects': {}, # (type, name) -> docname, labelid
'citations': {}, # name -> docname, labelid, lineno
- 'citation_refs': {}, # name -> list of docnames
+ 'citation_refs': {}, # labelid -> list of docnames
'labels': { # labelname -> docname, labelid, sectionname
'genindex': ('genindex', '', l_('Index')),
'modindex': ('py-modindex', '', l_('Module Index')),
@@ -589,8 +589,11 @@ class StandardDomain(Domain):
def note_citation_refs(self, env, docname, document):
# type: (BuildEnvironment, unicode, nodes.Node) -> None
for name, refs in iteritems(document.citation_refs):
- citation_refs = self.data['citation_refs'].setdefault(name, [])
- citation_refs.append(docname)
+ for ref in refs:
+ labelid = ref.get('refid')
+ if labelid:
+ citation_refs = self.data['citation_refs'].setdefault(labelid, [])
+ citation_refs.append(docname)
def note_labels(self, env, docname, document):
# type: (BuildEnvironment, unicode, nodes.Node) -> None
diff --git a/tests/roots/test-root/footnote.txt b/tests/roots/test-root/footnote.txt
index dc5e0b0da..9ea8d5082 100644
--- a/tests/roots/test-root/footnote.txt
+++ b/tests/roots/test-root/footnote.txt
@@ -23,6 +23,7 @@ citation
--------------------
[bar]_
+[baz_qux]_
footnotes in table
--------------------
@@ -50,6 +51,8 @@ footenotes
.. [bar] cite
+.. [baz_qux] citation including underscore
+
.. [#] footnote in table caption
.. [#] footnote in table header
diff --git a/tests/test_build_html.py b/tests/test_build_html.py
index 297334f0d..b2533629d 100644
--- a/tests/test_build_html.py
+++ b/tests/test_build_html.py
@@ -422,19 +422,21 @@ def test_static_output(app):
(".//li/a", "double"),
],
'footnote.html': [
- (".//a[@class='footnote-reference'][@href='#id8'][@id='id1']", r"\[1\]"),
- (".//a[@class='footnote-reference'][@href='#id9'][@id='id2']", r"\[2\]"),
+ (".//a[@class='footnote-reference'][@href='#id9'][@id='id1']", r"\[1\]"),
+ (".//a[@class='footnote-reference'][@href='#id10'][@id='id2']", r"\[2\]"),
(".//a[@class='footnote-reference'][@href='#foo'][@id='id3']", r"\[3\]"),
(".//a[@class='reference internal'][@href='#bar'][@id='id4']", r"\[bar\]"),
- (".//a[@class='footnote-reference'][@href='#id10'][@id='id5']", r"\[4\]"),
- (".//a[@class='footnote-reference'][@href='#id11'][@id='id6']", r"\[5\]"),
+ (".//a[@class='reference internal'][@href='#baz-qux'][@id='id5']", r"\[baz_qux\]"),
+ (".//a[@class='footnote-reference'][@href='#id11'][@id='id6']", r"\[4\]"),
+ (".//a[@class='footnote-reference'][@href='#id12'][@id='id7']", r"\[5\]"),
(".//a[@class='fn-backref'][@href='#id1']", r"\[1\]"),
(".//a[@class='fn-backref'][@href='#id2']", r"\[2\]"),
(".//a[@class='fn-backref'][@href='#id3']", r"\[3\]"),
(".//a[@class='fn-backref'][@href='#id4']", r"\[bar\]"),
- (".//a[@class='fn-backref'][@href='#id5']", r"\[4\]"),
- (".//a[@class='fn-backref'][@href='#id6']", r"\[5\]"),
- (".//a[@class='fn-backref'][@href='#id7']", r"\[6\]"),
+ (".//a[@class='fn-backref'][@href='#id5']", r"\[baz_qux\]"),
+ (".//a[@class='fn-backref'][@href='#id6']", r"\[4\]"),
+ (".//a[@class='fn-backref'][@href='#id7']", r"\[5\]"),
+ (".//a[@class='fn-backref'][@href='#id8']", r"\[6\]"),
],
'otherext.html': [
(".//h1", "Generated section"),
diff --git a/tests/test_build_html5.py b/tests/test_build_html5.py
index d24bac570..7fc91b9ec 100644
--- a/tests/test_build_html5.py
+++ b/tests/test_build_html5.py
@@ -297,19 +297,21 @@ def cached_etree_parse():
(".//li/a", "double"),
],
'footnote.html': [
- (".//a[@class='footnote-reference brackets'][@href='#id8'][@id='id1']", r"1"),
- (".//a[@class='footnote-reference brackets'][@href='#id9'][@id='id2']", r"2"),
+ (".//a[@class='footnote-reference brackets'][@href='#id9'][@id='id1']", r"1"),
+ (".//a[@class='footnote-reference brackets'][@href='#id10'][@id='id2']", r"2"),
(".//a[@class='footnote-reference brackets'][@href='#foo'][@id='id3']", r"3"),
(".//a[@class='reference internal'][@href='#bar'][@id='id4']", r"\[bar\]"),
- (".//a[@class='footnote-reference brackets'][@href='#id10'][@id='id5']", r"4"),
- (".//a[@class='footnote-reference brackets'][@href='#id11'][@id='id6']", r"5"),
+ (".//a[@class='reference internal'][@href='#baz-qux'][@id='id5']", r"\[baz_qux\]"),
+ (".//a[@class='footnote-reference brackets'][@href='#id11'][@id='id6']", r"4"),
+ (".//a[@class='footnote-reference brackets'][@href='#id12'][@id='id7']", r"5"),
(".//a[@class='fn-backref'][@href='#id1']", r"1"),
(".//a[@class='fn-backref'][@href='#id2']", r"2"),
(".//a[@class='fn-backref'][@href='#id3']", r"3"),
(".//a[@class='fn-backref'][@href='#id4']", r"bar"),
- (".//a[@class='fn-backref'][@href='#id5']", r"4"),
- (".//a[@class='fn-backref'][@href='#id6']", r"5"),
- (".//a[@class='fn-backref'][@href='#id7']", r"6"),
+ (".//a[@class='fn-backref'][@href='#id5']", r"baz_qux"),
+ (".//a[@class='fn-backref'][@href='#id6']", r"4"),
+ (".//a[@class='fn-backref'][@href='#id7']", r"5"),
+ (".//a[@class='fn-backref'][@href='#id8']", r"6"),
],
'otherext.html': [
(".//h1", "Generated section"),