mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Close #4980: latex: Improve label handling of LaTeX builder (table)
This commit is contained in:
@@ -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))
|
||||
|
@@ -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
|
||||
==== ====
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user