From 49063aa4ebf0bd115fb5cb32ea766fbcf69ccd67 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 29 Mar 2020 17:56:19 +0900 Subject: [PATCH] Fix html: a width of table was ignored on HTML builder (ref: #6564) --- CHANGES | 1 + sphinx/writers/html5.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index f0c19c85460..815848c913b 100644 --- a/CHANGES +++ b/CHANGES @@ -23,6 +23,7 @@ Bugs fixed * #7368: C++, comma operator in expressions, pack expansion in template argument lists, and more comprehensive error messages in some cases. * C, C++, fix crash and wrong duplicate warnings related to anon symbols. +* #6564: html: a width of table was ignored on HTML builder Testing -------- diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index f94dd60a390..80cedd3bdd8 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -734,11 +734,14 @@ def visit_table(self, node: Element) -> None: self._table_row_index = 0 + atts = {} classes = [cls.strip(' \t\n') for cls in self.settings.table_style.split(',')] classes.insert(0, "docutils") # compat if 'align' in node: classes.append('align-%s' % node['align']) - tag = self.starttag(node, 'table', CLASS=' '.join(classes)) + if 'width' in node: + atts['style'] = 'width: %s' % node['width'] + tag = self.starttag(node, 'table', CLASS=' '.join(classes), **atts) self.body.append(tag) def visit_row(self, node: Element) -> None: