summaryrefslogtreecommitdiff
path: root/docutils/writers/html4css1
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2017-02-13 21:40:21 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2017-02-13 21:40:21 +0000
commitd29d74774efbba52cfaad28f30073c0493eec6be (patch)
tree3249c5afe77cdd61d746b9bc429c545422cc3b63 /docutils/writers/html4css1
parentb65993730c58a97931d9083bb93ffa7d35a7664e (diff)
downloaddocutils-d29d74774efbba52cfaad28f30073c0493eec6be.tar.gz
Apply [ 125 ] respect automatic table column sizing also in html4css1.
Add a table with "auto"-width columns to the functional tests. git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk/docutils@8033 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/writers/html4css1')
-rw-r--r--docutils/writers/html4css1/__init__.py58
1 files changed, 30 insertions, 28 deletions
diff --git a/docutils/writers/html4css1/__init__.py b/docutils/writers/html4css1/__init__.py
index 8e2f12d3b..540e3748f 100644
--- a/docutils/writers/html4css1/__init__.py
+++ b/docutils/writers/html4css1/__init__.py
@@ -247,6 +247,29 @@ class HTMLTranslator(writers._html_base.HTMLTranslator):
def depart_authors(self, node):
self.depart_docinfo_item()
+ # use "width" argument insted of "style: 'width'":
+ def visit_colspec(self, node):
+ self.colspecs.append(node)
+ # "stubs" list is an attribute of the tgroup element:
+ node.parent.stubs.append(node.attributes.get('stub'))
+ #
+ def depart_colspec(self, node):
+ # write out <colgroup> when all colspecs are processed
+ if isinstance(node.next_node(descend=False, siblings=True),
+ nodes.colspec):
+ return
+ if 'colwidths-auto' in node.parent.parent['classes'] or (
+ 'colwidths-auto' in self.settings.table_style and
+ ('colwidths-given' not in node.parent.parent['classes'])):
+ return
+ total_width = sum(node['colwidth'] for node in self.colspecs)
+ self.body.append(self.starttag(node, 'colgroup'))
+ for node in self.colspecs:
+ colwidth = int(node['colwidth'] * 100.0 / total_width + 0.5)
+ self.body.append(self.emptytag(node, 'col',
+ width='%i%%' % colwidth))
+ self.body.append('</colgroup>\n')
+
# Compact lists:
# exclude definition lists and field lists (non-compact by default)
@@ -278,20 +301,6 @@ class HTMLTranslator(writers._html_base.HTMLTranslator):
self.body.append(' <span class="classifier-delimiter">:</span> ')
self.body.append(self.starttag(node, 'span', '', CLASS='classifier'))
- # rewritten in _html_base (support for "auto" width)
- def depart_colspec(self, node):
- pass
-
- def write_colspecs(self):
- width = 0
- for node in self.colspecs:
- width += node['colwidth']
- for node in self.colspecs:
- colwidth = int(node['colwidth'] * 100.0 / width + 0.5)
- self.body.append(self.emptytag(node, 'col',
- width='%i%%' % colwidth))
- self.colspecs = []
-
# ersatz for first/last pseudo-classes
def visit_definition(self, node):
self.body.append('</dt>\n')
@@ -761,24 +770,17 @@ class HTMLTranslator(writers._html_base.HTMLTranslator):
# hard-coded vertical alignment
def visit_tbody(self, node):
- self.write_colspecs()
- self.body.append(self.context.pop()) # '</colgroup>\n' or ''
self.body.append(self.starttag(node, 'tbody', valign='top'))
+ #
+ def depart_tbody(self, node):
+ self.body.append('</tbody>\n')
- # rewritten in _html_base
- def visit_tgroup(self, node):
- self.body.append(self.starttag(node, 'colgroup'))
- # Appended by thead or tbody:
- self.context.append('</colgroup>\n')
- node.stubs = []
-
- # rewritten in _html_base
+ # hard-coded vertical alignment
def visit_thead(self, node):
- self.write_colspecs()
- self.body.append(self.context.pop()) # '</colgroup>\n'
- # There may or may not be a <thead>; this is for <tbody> to use:
- self.context.append('')
self.body.append(self.starttag(node, 'thead', valign='bottom'))
+ #
+ def depart_thead(self, node):
+ self.body.append('</thead>\n')
class SimpleListChecker(writers._html_base.SimpleListChecker):