|
From: <mi...@us...> - 2017-10-06 14:41:09
|
Revision: 8184
http://sourceforge.net/p/docutils/code/8184
Author: milde
Date: 2017-10-06 14:41:07 +0000 (Fri, 06 Oct 2017)
Log Message:
-----------
Apply [ 121 ] Add a :width: option for the table directives.
Thanks to Brecht Machiels for the patch.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docs/ref/rst/directives.txt
trunk/docutils/docutils/parsers/rst/directives/tables.py
trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2017-10-06 09:00:00 UTC (rev 8183)
+++ trunk/docutils/HISTORY.txt 2017-10-06 14:41:07 UTC (rev 8184)
@@ -34,6 +34,10 @@
- Fix [ 281 ] Remove escaping backslashes in meta directive content.
+* docutils/parsers/rst/directives/tables.py:
+
+ - Apply [ 121 ] Add a :width: option for the table directives.
+
* docutils/transforms/frontmatter.py
- Add field name as class argument to generic docinfo fields unconditionally.
Modified: trunk/docutils/docs/ref/rst/directives.txt
===================================================================
--- trunk/docutils/docs/ref/rst/directives.txt 2017-10-06 09:00:00 UTC (rev 8183)
+++ trunk/docutils/docs/ref/rst/directives.txt 2017-10-06 14:41:07 UTC (rev 8184)
@@ -221,9 +221,6 @@
Used to reserve space or scale the image horizontally. As with "height"
above, when the "scale" option is also specified, they are combined.
- .. _length: restructuredtext.html#length-units
- .. _percentage: restructuredtext.html#percentage-units
-
``scale`` : integer percentage (the "%" symbol is optional)
The uniform scaling factor of the image. The default is "100 %", i.e.
no scaling.
@@ -795,6 +792,11 @@
(LaTeX, the HTML browser, ...).
See also the `table_style`_ configuration option.
+``width`` : `length`_ or `percentage`_ of the current line width
+ Forces the width of the table to the specified length or percentage
+ of the line width. If omitted, the renderer determines the width
+ of the table based on its contents.
+
and the common options `:class:`_ and `:name:`_.
.. _table_style: ../../user/config.html#table-style-html4css1-writer
@@ -866,6 +868,11 @@
whether to delegate the determination of column widths to the backend
(LaTeX, the HTML browser, ...).
+``width`` : `length`_ or `percentage`_ of the current line width
+ Forces the width of the table to the specified length or percentage
+ of the line width. If omitted, the renderer determines the width
+ of the table based on its contents.
+
``header-rows`` : integer
The number of rows of CSV data to use in the table header.
Defaults to 0.
@@ -971,6 +978,11 @@
whether to delegate the determination of column widths to the backend
(LaTeX, the HTML browser, ...).
+``width`` : `length`_ or `percentage`_ of the current line width
+ Forces the width of the table to the specified length or percentage
+ of the line width. If omitted, the renderer determines the width
+ of the table based on its contents.
+
``header-rows`` : integer
The number of rows of list data to use in the table header.
Defaults to 0.
@@ -1956,9 +1968,11 @@
.. _inline elements: ../doctree.html#inline-elements
.. _literal_block: ../doctree.html#literal-block
.. _legend: ../doctree.html#legend
+.. _length: restructuredtext.html#length-units
.. _line_block: ../doctree.html#line-block
.. _math_block: ../doctree.html#math-block
.. _pending: ../doctree.html#pending
+.. _percentage: restructuredtext.html#percentage-units
.. _raw: ../doctree.html#raw
.. _rubric: ../doctree.html#rubric
.. _sidebar: ../doctree.html#sidebar
Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/tables.py 2017-10-06 09:00:00 UTC (rev 8183)
+++ trunk/docutils/docutils/parsers/rst/directives/tables.py 2017-10-06 14:41:07 UTC (rev 8184)
@@ -35,6 +35,7 @@
option_spec = {'class': directives.class_option,
'name': directives.unchanged,
'align': align,
+ 'width': directives.length_or_percentage_or_unitless,
'widths': directives.value_or(('auto', 'grid'),
directives.positive_int_list)}
has_content = True
@@ -94,6 +95,10 @@
self.block_text, self.block_text), line=self.lineno)
raise SystemMessagePropagation(error)
+ def set_table_width(self, table_node):
+ if 'width' in self.options:
+ table_node['width'] = self.options.get('width')
+
@property
def widths(self):
return self.options.get('widths', '')
@@ -143,6 +148,7 @@
return [error]
table_node = node[0]
table_node['classes'] += self.options.get('class', [])
+ self.set_table_width(table_node)
if 'align' in self.options:
table_node['align'] = self.options.get('align')
tgroup = table_node[0]
@@ -169,6 +175,7 @@
option_spec = {'header-rows': directives.nonnegative_int,
'stub-columns': directives.nonnegative_int,
'header': directives.unchanged,
+ 'width': directives.length_or_percentage_or_unitless,
'widths': directives.value_or(('auto', ),
directives.positive_int_list),
'file': directives.path,
@@ -392,6 +399,7 @@
option_spec = {'header-rows': directives.nonnegative_int,
'stub-columns': directives.nonnegative_int,
+ 'width': directives.length_or_percentage_or_unitless,
'widths': directives.value_or(('auto', ),
directives.positive_int_list),
'class': directives.class_option,
@@ -422,6 +430,7 @@
if 'align' in self.options:
table_node['align'] = self.options.get('align')
table_node['classes'] += self.options.get('class', [])
+ self.set_table_width(table_node)
self.add_name(table_node)
if title:
table_node.insert(0, title)
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 2017-10-06 09:00:00 UTC (rev 8183)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py 2017-10-06 14:41:07 UTC (rev 8184)
@@ -192,6 +192,75 @@
"""],
["""\
.. table::
+ :width: 100 %
+
+ ============ ==============
+ col 1 col 2
+ ============ ==============
+""",
+"""\
+<document source="test data">
+ <table width="100%">
+ <tgroup cols="2">
+ <colspec colwidth="12">
+ <colspec colwidth="14">
+ <tbody>
+ <row>
+ <entry>
+ <paragraph>
+ col 1
+ <entry>
+ <paragraph>
+ col 2
+"""],
+["""\
+.. table::
+ :width: 100px
+
+ ============ ==============
+ col 1 col 2
+ ============ ==============
+""",
+"""\
+<document source="test data">
+ <table width="100px">
+ <tgroup cols="2">
+ <colspec colwidth="12">
+ <colspec colwidth="14">
+ <tbody>
+ <row>
+ <entry>
+ <paragraph>
+ col 1
+ <entry>
+ <paragraph>
+ col 2
+"""],
+["""\
+.. table::
+ :width: 321
+
+ ============ ==============
+ col 1 col 2
+ ============ ==============
+""",
+"""\
+<document source="test data">
+ <table width="321">
+ <tgroup cols="2">
+ <colspec colwidth="12">
+ <colspec colwidth="14">
+ <tbody>
+ <row>
+ <entry>
+ <paragraph>
+ col 1
+ <entry>
+ <paragraph>
+ col 2
+"""],
+["""\
+.. table::
:widths: 15, 25
============ ==============
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|