Close #4980: latex: Improve label handling of LaTeX builder (table)

This commit is contained in:
Takeshi KOMIYA
2018-05-19 00:26:18 +09:00
parent fdc0697690
commit 1b5e910059
3 changed files with 31 additions and 6 deletions

View File

@@ -52,6 +52,7 @@ LATEXSECTIONNAMES = ["part", "chapter", "section", "subsection",
HYPERLINK_SUPPORT_NODES = (
nodes.figure,
nodes.literal_block,
nodes.table,
)
DEFAULT_SETTINGS = {
@@ -1318,12 +1319,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
def depart_table(self, node):
# type: (nodes.Node) -> None
labels = '' # type: unicode
for labelid in self.pop_hyperlink_ids('table'):
labels += self.hypertarget(labelid, anchor=False)
if node['ids']:
labels += self.hypertarget(node['ids'][0], anchor=False)
labels = self.hypertarget_to(node)
table_type = self.table.get_table_type()
table = self.render(table_type + '.tex_t',
dict(table=self.table, labels=labels))

View File

@@ -30,3 +30,24 @@ code-blocks
:name: codeblock3
blah blah blah
tables
------
.. _table1:
.. _table2:
.. table:: table caption
==== ====
head head
cell cell
==== ====
.. table:: table caption
:name: table3
==== ====
head head
cell cell
==== ====

View File

@@ -1288,3 +1288,11 @@ def test_latex_labels(app, status, warning):
r'\label{\detokenize{index:codeblock1}}}' in result)
assert (r'\def\sphinxLiteralBlockLabel{'
r'\label{\detokenize{index:codeblock3}}}' in result)
# tables
assert (r'\sphinxcaption{table caption}'
r'\label{\detokenize{index:id2}}'
r'\label{\detokenize{index:table2}}'
r'\label{\detokenize{index:table1}}' in result)
assert (r'\sphinxcaption{table caption}'
r'\label{\detokenize{index:table3}}' in result)