|
From: <mi...@us...> - 2016-07-28 21:52:16
|
Revision: 7958
http://sourceforge.net/p/docutils/code/7958
Author: milde
Date: 2016-07-28 21:52:14 +0000 (Thu, 28 Jul 2016)
Log Message:
-----------
Clear up and document patch [ 120 ].
The colwidths argument for <tgroup> violates the docutils.dtd.
As the "auto"/"given" tags may be ignored by the writers, they may be
stored as classes instead.
The default case (grid for tables, equal widths for ListTable and CSVTable
does not need/get a tag. This way, writers can decide whether to leave
column width determination to the backend when the class "colwidths-auto" is
set (opt-in) or by default (opt-out with "colwidths-given").
Modified Paths:
--------------
trunk/docutils/docutils/parsers/rst/directives/tables.py
trunk/docutils/docutils/parsers/rst/states.py
trunk/docutils/docutils/writers/html_plain/__init__.py
trunk/docutils/test/functional/expected/math_output_mathml.xhtml
trunk/docutils/test/functional/expected/standalone_rst_html_plain.html
trunk/docutils/test/functional/input/data/math.txt
trunk/docutils/test/functional/input/standalone_rst_html_plain.txt
trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/tables.py 2016-07-28 20:59:14 UTC (rev 7957)
+++ trunk/docutils/docutils/parsers/rst/directives/tables.py 2016-07-28 21:52:14 UTC (rev 7958)
@@ -94,7 +94,7 @@
@property
def widths(self):
- return self.options.get('widths', 'auto')
+ return self.options.get('widths', '')
def get_column_widths(self, max_cols):
if type(self.widths) == list:
@@ -114,8 +114,10 @@
raise SystemMessagePropagation(error)
if self.widths == 'auto':
widths = 'auto'
+ elif self.widths: # "grid" or list of integers
+ widths = 'given'
else:
- widths = 'given'
+ widths = self.widths
return widths, col_widths
def extend_short_rows_with_empty_cells(self, columns, parts):
@@ -153,10 +155,13 @@
if child.tagname == 'colspec']
for colspec, col_width in zip(colspecs, self.widths):
colspec['colwidth'] = col_width
+ # @@@ the colwidths argument for <tgroup> is not part of the
+ # XML Exchange Table spec (https://www.oasis-open.org/specs/tm9901.htm)
+ # and hence violates the docutils.dtd.
if self.widths == 'auto':
- tgroup['colwidths'] = 'auto'
- else:
- tgroup['colwidths'] = 'given'
+ table_node['classes'] += ['colwidths-auto']
+ elif self.widths: # "grid" or list of integers
+ table_node['classes'] += ['colwidths-given']
self.add_name(table_node)
if title:
table_node.insert(0, title)
@@ -468,7 +473,9 @@
def build_table_from_list(self, table_data, widths, col_widths, header_rows,
stub_columns):
table = nodes.table()
- tgroup = nodes.tgroup(cols=len(col_widths), colwidths=widths)
+ if widths:
+ table['classes'] += ['colwidths-%s' % widths]
+ tgroup = nodes.tgroup(cols=len(col_widths))
table += tgroup
for col_width in col_widths:
colspec = nodes.colspec()
Modified: trunk/docutils/docutils/parsers/rst/states.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/states.py 2016-07-28 20:59:14 UTC (rev 7957)
+++ trunk/docutils/docutils/parsers/rst/states.py 2016-07-28 21:52:14 UTC (rev 7958)
@@ -1764,10 +1764,12 @@
line=startline+offset)
return [error]
- def build_table(self, tabledata, tableline, stub_columns=0, widths='auto'):
+ def build_table(self, tabledata, tableline, stub_columns=0, widths=None):
colwidths, headrows, bodyrows = tabledata
table = nodes.table()
- tgroup = nodes.tgroup(cols=len(colwidths), colwidths=widths)
+ if widths:
+ table['classes'] += ['colwidths-%s' % widths]
+ tgroup = nodes.tgroup(cols=len(colwidths))
table += tgroup
for colwidth in colwidths:
colspec = nodes.colspec(colwidth=colwidth)
Modified: trunk/docutils/docutils/writers/html_plain/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/html_plain/__init__.py 2016-07-28 20:59:14 UTC (rev 7957)
+++ trunk/docutils/docutils/writers/html_plain/__init__.py 2016-07-28 21:52:14 UTC (rev 7958)
@@ -634,11 +634,9 @@
pass
def write_colspecs(self):
- width = 0
+ total_width = sum(node['colwidth'] for node in self.colspecs)
for node in self.colspecs:
- width += node['colwidth']
- for node in self.colspecs:
- colwidth = int(node['colwidth'] * 100.0 / width + 0.5)
+ colwidth = int(node['colwidth'] * 100.0 / total_width + 0.5)
self.body.append(self.emptytag(node, 'col',
style='width: %i%%' % colwidth))
self.colspecs = []
Modified: trunk/docutils/test/functional/expected/math_output_mathml.xhtml
===================================================================
--- trunk/docutils/test/functional/expected/math_output_mathml.xhtml 2016-07-28 20:59:14 UTC (rev 7957)
+++ trunk/docutils/test/functional/expected/math_output_mathml.xhtml 2016-07-28 21:52:14 UTC (rev 7958)
@@ -95,7 +95,7 @@
physical system changes in time.</p>
<dl>
<dt>Math-Accents:</dt>
-<dd><table class="borderless">
+<dd><table class="colwidths-given borderless">
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
@@ -205,7 +205,7 @@
<p>Cases with the <a class="reference external" href="ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf">AMSmath</a> <span class="docutils literal">cases</span> environment (not (yet) supported by
HTML writers with <span class="docutils literal"><span class="pre">--math-output=MathML</span></span>):</p>
<div class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<span class="docutils literal">functional/input/data/math.txt</span>, line 107)</p>
+<p class="system-message-title">System Message: ERROR/3 (<span class="docutils literal">functional/input/data/math.txt</span>, line 108)</p>
<p>
Environment not supported! Supported environment: "matrix".</p>
<pre class="literal-block">
Modified: trunk/docutils/test/functional/expected/standalone_rst_html_plain.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html_plain.html 2016-07-28 20:59:14 UTC (rev 7957)
+++ trunk/docutils/test/functional/expected/standalone_rst_html_plain.html 2016-07-28 21:52:14 UTC (rev 7958)
@@ -1057,7 +1057,7 @@
<div class="section" id="list-tables">
<h2><a class="toc-backref" href="#id76"><span class="sectnum">2.22</span> List Tables</a></h2>
<p>Here's a list table exercising all features:</p>
-<table class="test">
+<table class="colwidths-given test">
<caption>list table with integral header</caption>
<colgroup>
<col style="width: 17%" />
@@ -1416,33 +1416,6 @@
from the <a class="reference external" href="http://tug.ctan.org/tex-archive/macros/latex/contrib/booktabs/booktabs.pdf">booktabs</a> <a class="footnote-reference brackets" href="#id33" id="id34">8</a> LaTeX package.</p>
<table class="booktabs">
<colgroup>
-<col style="width: 31%" />
-<col style="width: 31%" />
-<col style="width: 38%" />
-</colgroup>
-<tbody>
-<tr><td><p>False</p></td>
-<td><p>False</p></td>
-<td><p>False</p></td>
-</tr>
-<tr><td><p>True</p></td>
-<td><p>False</p></td>
-<td><p>True</p></td>
-</tr>
-<tr><td><p>False</p></td>
-<td><p>True</p></td>
-<td><p>True</p></td>
-</tr>
-<tr><td><p>True</p></td>
-<td><p>True</p></td>
-<td><p>True</p></td>
-</tr>
-</tbody>
-</table>
-<p>This table also uses the "align-right" class argument, to right-align
-the table:</p>
-<table class="booktabs align-right">
-<colgroup>
<col style="width: 29%" />
<col style="width: 29%" />
<col style="width: 41%" />
Modified: trunk/docutils/test/functional/input/data/math.txt
===================================================================
--- trunk/docutils/test/functional/input/data/math.txt 2016-07-28 20:59:14 UTC (rev 7957)
+++ trunk/docutils/test/functional/input/data/math.txt 2016-07-28 21:52:14 UTC (rev 7958)
@@ -49,6 +49,7 @@
Math-Accents:
.. list-table::
:class: borderless
+ :widths: 26 26 26
* - :math:`\acute{a}` ``\acute{a}``
- :math:`\dot{t}` ``\dot{t}``
Modified: trunk/docutils/test/functional/input/standalone_rst_html_plain.txt
===================================================================
--- trunk/docutils/test/functional/input/standalone_rst_html_plain.txt 2016-07-28 20:59:14 UTC (rev 7957)
+++ trunk/docutils/test/functional/input/standalone_rst_html_plain.txt 2016-07-28 21:52:14 UTC (rev 7958)
@@ -167,18 +167,6 @@
.. class:: booktabs
-===== ===== ======
-False False False
-True False True
-False True True
-True True True
-===== ===== ======
-
-This table also uses the "align-right" class argument, to right-align
-the table:
-
-.. class:: booktabs align-right
-
===== ===== =======
A B A or B
===== ===== =======
@@ -188,7 +176,6 @@
True True True
===== ===== =======
-
"Booktabs" style table, numbered and centre-aligned:
.. table:: I/O values
Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py 2016-07-28 20:59:14 UTC (rev 7957)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py 2016-07-28 21:52:14 UTC (rev 7958)
@@ -71,7 +71,7 @@
<table classes="custom" ids="tab-truth-not" names="tab:truth.not">
<title>
Truth table for "not"
- <tgroup cols="2" colwidths="auto">
+ <tgroup cols="2">
<colspec colwidth="5">
<colspec colwidth="5">
<thead>
@@ -109,7 +109,7 @@
"""\
<document source="test data">
<table>
- <tgroup cols="2" colwidths="auto">
+ <tgroup cols="2">
<colspec colwidth="10">
<colspec colwidth="10">
<tbody>
@@ -143,7 +143,7 @@
<problematic ids="id2" refid="id1">
*
error
- <tgroup cols="2" colwidths="auto">
+ <tgroup cols="2">
<colspec colwidth="6">
<colspec colwidth="5">
<tbody>
@@ -194,8 +194,8 @@
""",
"""\
<document source="test data">
- <table>
- <tgroup cols="2" colwidths="given">
+ <table classes="colwidths-given">
+ <tgroup cols="2">
<colspec colwidth="15">
<colspec colwidth="25">
<tbody>
@@ -217,8 +217,8 @@
""",
"""\
<document source="test data">
- <table>
- <tgroup cols="2" colwidths="given">
+ <table classes="colwidths-given">
+ <tgroup cols="2">
<colspec colwidth="10">
<colspec colwidth="20">
<tbody>
@@ -240,8 +240,8 @@
""",
"""\
<document source="test data">
- <table>
- <tgroup cols="2" colwidths="auto">
+ <table classes="colwidths-auto">
+ <tgroup cols="2">
<colspec colwidth="14">
<colspec colwidth="19">
<tbody>
@@ -263,8 +263,8 @@
""",
"""\
<document source="test data">
- <table>
- <tgroup cols="2" colwidths="given">
+ <table classes="colwidths-given">
+ <tgroup cols="2">
<colspec colwidth="14">
<colspec colwidth="19">
<tbody>
@@ -287,7 +287,7 @@
"""\
<document source="test data">
<table align="center">
- <tgroup cols="2" colwidths="auto">
+ <tgroup cols="2">
<colspec colwidth="6">
<colspec colwidth="5">
<tbody>
@@ -316,10 +316,10 @@
""",
"""\
<document source="test data">
- <table>
+ <table classes="colwidths-given">
<title>
inline with integral header
- <tgroup cols="3" colwidths="given">
+ <tgroup cols="3">
<colspec colwidth="10" stub="1">
<colspec colwidth="20">
<colspec colwidth="30">
@@ -376,10 +376,10 @@
""",
"""\
<document source="test data">
- <table>
+ <table classes="colwidths-given">
<title>
inline with separate header
- <tgroup cols="3" colwidths="given">
+ <tgroup cols="3">
<colspec colwidth="10">
<colspec colwidth="20">
<colspec colwidth="30">
@@ -423,7 +423,7 @@
<table>
<title>
complex internal structure
- <tgroup cols="3" colwidths="auto">
+ <tgroup cols="3">
<colspec colwidth="33">
<colspec colwidth="33">
<colspec colwidth="33">
@@ -477,7 +477,7 @@
<table>
<title>
short rows
- <tgroup cols="3" colwidths="auto">
+ <tgroup cols="3">
<colspec colwidth="33">
<colspec colwidth="33">
<colspec colwidth="33">
@@ -514,7 +514,7 @@
<table>
<title>
short rows
- <tgroup cols="3" colwidths="auto">
+ <tgroup cols="3">
<colspec colwidth="33">
<colspec colwidth="33">
<colspec colwidth="33">
@@ -555,7 +555,7 @@
<table>
<title>
non-ASCII characters
- <tgroup cols="1" colwidths="auto">
+ <tgroup cols="1">
<colspec colwidth="100">
<tbody>
<row>
@@ -575,7 +575,7 @@
<table align="center">
<title>
center aligned
- <tgroup cols="2" colwidths="auto">
+ <tgroup cols="2">
<colspec colwidth="50">
<colspec colwidth="50">
<tbody>
@@ -684,7 +684,7 @@
<problematic ids="id2" refid="id1">
*
title
- <tgroup cols="3" colwidths="auto">
+ <tgroup cols="3">
<colspec colwidth="33">
<colspec colwidth="33">
<colspec colwidth="33">
@@ -809,7 +809,7 @@
<table>
<title>
good delimiter
- <tgroup cols="3" colwidths="auto">
+ <tgroup cols="3">
<colspec colwidth="33">
<colspec colwidth="33">
<colspec colwidth="33">
@@ -827,7 +827,7 @@
<table>
<title>
good delimiter
- <tgroup cols="3" colwidths="auto">
+ <tgroup cols="3">
<colspec colwidth="33">
<colspec colwidth="33">
<colspec colwidth="33">
@@ -845,7 +845,7 @@
<table>
<title>
good delimiter
- <tgroup cols="3" colwidths="auto">
+ <tgroup cols="3">
<colspec colwidth="33">
<colspec colwidth="33">
<colspec colwidth="33">
@@ -863,7 +863,7 @@
<table>
<title>
good delimiter
- <tgroup cols="3" colwidths="auto">
+ <tgroup cols="3">
<colspec colwidth="33">
<colspec colwidth="33">
<colspec colwidth="33">
@@ -970,7 +970,7 @@
<table>
<title>
good encoding
- <tgroup cols="3" colwidths="auto">
+ <tgroup cols="3">
<colspec colwidth="33">
<colspec colwidth="33">
<colspec colwidth="33">
@@ -1056,10 +1056,10 @@
""",
"""\
<document source="test data">
- <table>
+ <table classes="colwidths-given">
<title>
list table with integral header
- <tgroup cols="3" colwidths="given">
+ <tgroup cols="3">
<colspec colwidth="10" stub="1">
<colspec colwidth="20">
<colspec colwidth="30">
@@ -1122,10 +1122,10 @@
""",
"""\
<document source="test data">
- <table>
+ <table classes="colwidths-auto">
<title>
list table with integral header
- <tgroup cols="3" colwidths="auto">
+ <tgroup cols="3">
<colspec colwidth="33" stub="1">
<colspec colwidth="33">
<colspec colwidth="33">
@@ -1176,7 +1176,7 @@
<table>
<title>
list table with integral header
- <tgroup cols="3" colwidths="auto">
+ <tgroup cols="3">
<colspec colwidth="33" stub="1">
<colspec colwidth="33">
<colspec colwidth="33">
@@ -1238,7 +1238,7 @@
<table align="center">
<title>
center aligned
- <tgroup cols="2" colwidths="auto">
+ <tgroup cols="2">
<colspec colwidth="50">
<colspec colwidth="50">
<tbody>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|