diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-12-22 18:47:30 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-12-22 18:47:30 +0900 |
commit | 5640cf879f91c8ca5e71b68ab5a5fd24b536703a (patch) | |
tree | 6fc2107d8adc1ade4f9a8ca260db4e156fdde609 /sphinx/writers | |
parent | e83bb29789a093c651a255a509430a03346a5afb (diff) | |
parent | 43c089fd28dfdc33cc67b364724db51d3f5c1804 (diff) | |
download | sphinx-git-5640cf879f91c8ca5e71b68ab5a5fd24b536703a.tar.gz |
Merge branch '2.0'
Diffstat (limited to 'sphinx/writers')
-rw-r--r-- | sphinx/writers/html.py | 2 | ||||
-rw-r--r-- | sphinx/writers/html5.py | 2 | ||||
-rw-r--r-- | sphinx/writers/latex.py | 32 | ||||
-rw-r--r-- | sphinx/writers/texinfo.py | 6 |
4 files changed, 30 insertions, 12 deletions
diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index eac446793..e5d00fd2c 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -89,7 +89,7 @@ class HTMLTranslator(SphinxTranslator, BaseTranslator): self.permalink_text = self.config.html_add_permalinks # support backwards-compatible setting to a bool if not isinstance(self.permalink_text, str): - self.permalink_text = self.permalink_text and '¶' or '' + self.permalink_text = '¶' if self.permalink_text else '' self.permalink_text = self.encode(self.permalink_text) self.secnumber_suffix = self.config.html_secnumber_suffix self.param_separator = '' diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index 438f161f7..e6bf0c9b2 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -61,7 +61,7 @@ class HTML5Translator(SphinxTranslator, BaseTranslator): self.permalink_text = self.config.html_add_permalinks # support backwards-compatible setting to a bool if not isinstance(self.permalink_text, str): - self.permalink_text = self.permalink_text and '¶' or '' + self.permalink_text = '¶' if self.permalink_text else '' self.permalink_text = self.encode(self.permalink_text) self.secnumber_suffix = self.config.html_secnumber_suffix self.param_separator = '' diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index e5573c182..db326406d 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -631,7 +631,7 @@ class LaTeXTranslator(SphinxTranslator): latex_engine=self.config.latex_engine) self.context = [] # type: List[Any] self.descstack = [] # type: List[str] - self.table = None # type: Table + self.tables = [] # type: List[Table] self.next_table_colspec = None # type: str self.bodystack = [] # type: List[List[str]] self.footnote_restricted = None # type: nodes.Element @@ -665,7 +665,7 @@ class LaTeXTranslator(SphinxTranslator): def hypertarget(self, id: str, withdoc: bool = True, anchor: bool = True) -> str: if withdoc: id = self.curfilestack[-1] + ':' + id - return (anchor and '\\phantomsection' or '') + \ + return ('\\phantomsection' if anchor else '') + \ '\\label{%s}' % self.idescape(id) def hypertarget_to(self, node: Element, anchor: bool = False) -> str: @@ -749,6 +749,14 @@ class LaTeXTranslator(SphinxTranslator): return renderer.render(template_name, variables) + @property + def table(self) -> Table: + """Get current table.""" + if self.tables: + return self.tables[-1] + else: + return None + def visit_document(self, node: Element) -> None: self.curfilestack.append(node.get('docname', '')) if self.first_document == 1: @@ -1045,11 +1053,21 @@ class LaTeXTranslator(SphinxTranslator): raise nodes.SkipNode def visit_table(self, node: Element) -> None: - if self.table: + if len(self.tables) == 1: + if self.table.get_table_type() == 'longtable': + raise UnsupportedError( + '%s:%s: longtable does not support nesting a table.' % + (self.curfilestack[-1], node.line or '')) + else: + # change type of parent table to tabular + # see https://groups.google.com/d/msg/sphinx-users/7m3NeOBixeo/9LKP2B4WBQAJ + self.table.has_problematic = True + elif len(self.tables) > 2: raise UnsupportedError( - '%s:%s: nested tables are not yet implemented.' % + '%s:%s: deeply nested tables are not implemented.' % (self.curfilestack[-1], node.line or '')) - self.table = Table(node) + + self.tables.append(Table(node)) if self.next_table_colspec: self.table.colspec = '{%s}\n' % self.next_table_colspec if 'colwidths-given' in node.get('classes', []): @@ -1066,7 +1084,7 @@ class LaTeXTranslator(SphinxTranslator): self.body.append(table) self.body.append("\n") - self.table = None + self.tables.pop() def visit_colspec(self, node: Element) -> None: self.table.colcount += 1 @@ -1491,7 +1509,7 @@ class LaTeXTranslator(SphinxTranslator): elif isinstance(node[0], nodes.image) and 'width' in node[0]: length = self.latex_image_length(node[0]['width']) self.body.append('\\begin{wrapfigure}{%s}{%s}\n\\centering' % - (node['align'] == 'right' and 'r' or 'l', length or '0pt')) + ('r' if node['align'] == 'right' else 'l', length or '0pt')) self.context.append('\\end{wrapfigure}\n') elif self.in_minipage: self.body.append('\n\\begin{center}') diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index fd33c9fe4..2a631f176 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -240,7 +240,7 @@ class TexinfoTranslator(SphinxTranslator): title = self.settings.title # type: str if not title: title_node = self.document.next_node(nodes.title) - title = (title_node and title_node.astext()) or '<untitled>' + title = title_node.astext() if title_node else '<untitled>' elements['title'] = self.escape_id(title) or '<untitled>' # filename if not elements['filename']: @@ -290,7 +290,7 @@ class TexinfoTranslator(SphinxTranslator): # each section is also a node for section in self.document.traverse(nodes.section): title = cast(nodes.TextElement, section.next_node(nodes.Titular)) - name = (title and title.astext()) or '<untitled>' + name = title.astext() if title else '<untitled>' section['node_name'] = add_node_name(name) def collect_node_menus(self) -> None: @@ -304,7 +304,7 @@ class TexinfoTranslator(SphinxTranslator): node_menus[node['node_name']] = entries # try to find a suitable "Top" node title = self.document.next_node(nodes.title) - top = (title and title.parent) or self.document + top = title.parent if title else self.document if not isinstance(top, (nodes.document, nodes.section)): top = self.document if top is not self.document: |