From 235b8211307d14e2035f414576a9327635121bee Mon Sep 17 00:00:00 2001
From: milde
Date: Mon, 13 Feb 2017 21:40:21 +0000
Subject: [PATCH] Apply [ 125 ] respect automatic table column sizing also in
html4css1.
Add a table with "auto"-width columns to the functional tests.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8033 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
---
docutils/HISTORY.txt | 6 +-
docutils/docutils/writers/html4css1/__init__.py | 58 ++++++++---------
.../expected/standalone_rst_docutils_xml.xml | 73 +++++++++++++++++++++-
.../expected/standalone_rst_html4css1.html | 29 +++++++++
.../functional/expected/standalone_rst_html5.html | 58 ++++++++---------
.../expected/standalone_rst_pseudoxml.txt | 65 ++++++++++++++++++-
docutils/test/functional/input/data/standard.txt | 15 +++++
.../test/functional/input/standalone_rst_html5.txt | 15 -----
8 files changed, 242 insertions(+), 77 deletions(-)
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt
index b60339e9d..c6aa10948 100644
--- a/docutils/HISTORY.txt
+++ b/docutils/HISTORY.txt
@@ -63,6 +63,10 @@ Changes Since 0.13.1
- Provide default title in metadata (required by HTML5).
+* docutils/writers/html4css1/__init__.py
+
+ - Apply [ 125 ] HTML writer: respect automatic table column sizing.
+
* tools/rst2html4.py: New front-end.
* tools/dev/generate_punctuation_chars.py: New skript
@@ -166,7 +170,7 @@ Release 0.13.1 (2016-12-09)
- Fix [ 224 ] Fix rowspan support for tables.
- Let LaTeX determine the column widths in tables with "colwidths-auto".
- Not suited for with multi-paragraph cells!
+ Not suited for multi-paragraph cells!
* docutils/writers/odf_odt/__init__.py
diff --git a/docutils/docutils/writers/html4css1/__init__.py b/docutils/docutils/writers/html4css1/__init__.py
index 8e2f12d3b..540e3748f 100644
--- a/docutils/docutils/writers/html4css1/__init__.py
+++ b/docutils/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 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('\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(' : ')
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('\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()) # '\n' or ''
self.body.append(self.starttag(node, 'tbody', valign='top'))
+ #
+ def depart_tbody(self, node):
+ self.body.append('\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('\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()) # '\n'
- # There may or may not be a ; this is for to use:
- self.context.append('')
self.body.append(self.starttag(node, 'thead', valign='bottom'))
+ #
+ def depart_thead(self, node):
+ self.body.append('\n')
class SimpleListChecker(writers._html_base.SimpleListChecker):
diff --git a/docutils/test/functional/expected/standalone_rst_docutils_xml.xml b/docutils/test/functional/expected/standalone_rst_docutils_xml.xml
index 8abee925e..0652a71c3 100644
--- a/docutils/test/functional/expected/standalone_rst_docutils_xml.xml
+++ b/docutils/test/functional/expected/standalone_rst_docutils_xml.xml
@@ -1003,6 +1003,75 @@ Python-specific usage examples; begun with ">>>"
+ With the "widths" argument "auto" (or "class" value "colwidths-auto"),
+ column widths are determined by the backend (if supported by the
+ writer/backend).
+
+
+
+
+
+
+
+
+ A
+
+
+ B
+
+
+ A or B
+
+
+
+
+
+
+ False
+
+
+ False
+
+
+ False
+
+
+
+
+ True
+
+
+ False
+
+
+ True
+
+
+
+
+ False
+
+
+ True
+
+
+ True
+
+
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+
+
+
2.14.3 Admonitions
@@ -1604,10 +1673,10 @@ Comments may contain non-ASCII characters: ä ö ü æ ø å
Hyperlink target "image-target-3" is not referenced.
-
+
Hyperlink target "docutils" is not referenced.
-
+
Hyperlink target "hyperlink targets" is not referenced.
diff --git a/docutils/test/functional/expected/standalone_rst_html4css1.html b/docutils/test/functional/expected/standalone_rst_html4css1.html
index c45f2586c..3c64233f5 100644
--- a/docutils/test/functional/expected/standalone_rst_html4css1.html
+++ b/docutils/test/functional/expected/standalone_rst_html4css1.html
@@ -724,6 +724,35 @@ directive:
+With the "widths" argument "auto" (or "class" value "colwidths-auto"),
+column widths are determined by the backend (if supported by the
+writer/backend).
+
+
+A |
+B |
+A or B |
+
+
+
+False |
+False |
+False |
+
+True |
+False |
+True |
+
+False |
+True |
+True |
+
+True |
+True |
+True |
+
+
+
diff --git a/docutils/test/functional/expected/standalone_rst_html5.html b/docutils/test/functional/expected/standalone_rst_html5.html
index c3691ba0d..bb5e5a229 100644
--- a/docutils/test/functional/expected/standalone_rst_html5.html
+++ b/docutils/test/functional/expected/standalone_rst_html5.html
@@ -706,6 +706,35 @@ directive:
+
With the "widths" argument "auto" (or "class" value "colwidths-auto"),
+column widths are determined by the backend (if supported by the
+writer/backend).
+
+
+A |
+B |
+A or B |
+
+
+
+False |
+False |
+False |
+
+True |
+False |
+True |
+
+False |
+True |
+True |
+
+True |
+True |
+True |
+
+
+
@@ -1414,35 +1443,6 @@ setting (or command line argument).
Currently, referencing to the table by number is not supported. This is a
common request and already on the TODO list.
-
With the "widths" argument "auto" (or "class" value "colwidths-auto"),
-column widths are determined by the browser.
-
-
-A |
-B |
-A or B |
-
-
-
-False |
-False |
-False |
-
-True |
-False |
-True |
-
-False |
-True |
-True |
-
-True |
-True |
-True |
-
-
-
-
A table with "booktabs" class value, is rendered similar to the style
from the booktabs LaTeX package.
diff --git a/docutils/test/functional/expected/standalone_rst_pseudoxml.txt b/docutils/test/functional/expected/standalone_rst_pseudoxml.txt
index 2fb686d77..6782b23ae 100644
--- a/docutils/test/functional/expected/standalone_rst_pseudoxml.txt
+++ b/docutils/test/functional/expected/standalone_rst_pseudoxml.txt
@@ -1454,6 +1454,67 @@
False
+
+ With the "widths" argument "auto" (or "class" value "colwidths-auto"),
+ column widths are determined by the backend (if supported by the
+ writer/backend).
+
+
+
+
+
+
+
+
+
+ A
+
+
+ B
+
+
+ A or B
+
+
+
+
+ False
+
+
+ False
+
+
+ False
+
+
+
+ True
+
+
+ False
+
+
+ True
+
+
+
+ False
+
+
+ True
+
+
+ True
+
+
+
+ True
+
+
+ True
+
+
+ True
@@ -2202,9 +2263,9 @@
Hyperlink target "image-target-3" is not referenced.
-
+
Hyperlink target "docutils" is not referenced.
-
+
Hyperlink target "hyperlink targets" is not referenced.
diff --git a/docutils/test/functional/input/data/standard.txt b/docutils/test/functional/input/data/standard.txt
index 77433b526..fb3ad9491 100644
--- a/docutils/test/functional/input/data/standard.txt
+++ b/docutils/test/functional/input/data/standard.txt
@@ -630,6 +630,21 @@ directive:
True False
===== =====
+With the "widths" argument "auto" (or "class" value "colwidths-auto"),
+column widths are determined by the backend (if supported by the
+writer/backend).
+
+.. table::
+ :widths: auto
+
+ ======= ======= ==========
+ A B A or B
+ ======= ======= ==========
+ False False False
+ True False True
+ False True True
+ True True True
+ ======= ======= ==========
Admonitions
diff --git a/docutils/test/functional/input/standalone_rst_html5.txt b/docutils/test/functional/input/standalone_rst_html5.txt
index a87d9fa05..fe000be75 100644
--- a/docutils/test/functional/input/standalone_rst_html5.txt
+++ b/docutils/test/functional/input/standalone_rst_html5.txt
@@ -157,21 +157,6 @@ setting (or command line argument).
Currently, referencing to the table by number is not supported. This is a
common request and already on the `TODO list`.
-* With the "widths" argument "auto" (or "class" value "colwidths-auto"),
- column widths are determined by the browser.
-
- .. table::
- :widths: auto
-
- ======= ======= ==========
- A B A or B
- ======= ======= ==========
- False False False
- True False True
- False True True
- True True True
- ======= ======= ==========
-
* A table with "booktabs" class value, is rendered similar to the style
from the booktabs_ LaTeX package.
--
2.11.4.GIT