|
From: <mi...@us...> - 2023-06-27 20:04:18
|
Revision: 9414
http://sourceforge.net/p/docutils/code/9414
Author: milde
Date: 2023-06-27 20:04:16 +0000 (Tue, 27 Jun 2023)
Log Message:
-----------
Use the same format for :header: option and main data in "csv-table" directive.
The separate HeaderDialect was introduced 2004-06-17 (in the sandbox)
for unknown reasons while the documentation always said
"Must use the same CSV format as the main CSV data."
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.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 2023-06-27 20:04:02 UTC (rev 9413)
+++ trunk/docutils/HISTORY.txt 2023-06-27 20:04:16 UTC (rev 9414)
@@ -33,6 +33,14 @@
.. _UTF-8 mode: https://docs.python.org/3/library/os.html#utf8-mode
.. _input encoding: docs/api/publisher.html#encodings
+* docutils/parsers/rst/directives/tables.py
+
+ - Use the same CSV format for the ``:header:`` option and the main data
+ of the "csv-table" directive.
+
+ - Move `parsers.rst.directives.Table.process_header_option()` to
+ `parsers.rst.directives.CSVTable`.
+
* docutils/utils/roman.py
- Update to version `1.4 <https://pypi.org/project/roman/4.1/>`__.
@@ -45,6 +53,7 @@
* docutils/writers/s5_html/__init__.py
- Warn if the S5 writer cannot copy the theme files.
+
- Programmatic customization of "theme_url__" setting no longer
overridden by the default for "theme__".
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2023-06-27 20:04:02 UTC (rev 9413)
+++ trunk/docutils/RELEASE-NOTES.txt 2023-06-27 20:04:16 UTC (rev 9414)
@@ -108,18 +108,9 @@
Misc
----
-* "csv-table_" directive:
+* Remove `parsers.rst.directives.CSVTable.HeaderDialect`
+ in Docutils 0.22.
- - Use the same CSV format for the main CSV data and the :header: option
- (as specified in the documentation since addition of "csv-table_")
- in Docutils 0.21.
-
- - Move `parsers.rst.directives.Table.process_header_option()` to
- `parsers.rst.directives.CSVTable` in Docutils 0.21.
-
- - Remove `parsers.rst.directives.CSVTable.HeaderDialect`
- in Docutils 0.22.
-
* Remove the compatibility hacks `nodes.reprunicode` and `nodes.ensure_str()`
in Docutils 0.21 or later. They are not required with Python 3.x.
@@ -208,12 +199,14 @@
.. _input encoding: docs/api/publisher.html#encodings
* "html5" writer:
-
Stop setting the "footnote-reference" class value for footnote references.
- Use the CSS selector ``[role="doc-noteref"]`` instead of
- ``.footnote-reference`` (see minimal.css for examples).
+ You can use the CSS selector ``[role="doc-noteref"]``
+ since Docutils 0.18 (see minimal.css for examples).
+* Use the same CSV format for the ``:header:`` option and the main data
+ of the "csv-table_" directive.
+
Release 0.20.1 (2023-05-17)
===========================
Modified: trunk/docutils/docs/ref/rst/directives.txt
===================================================================
--- trunk/docutils/docs/ref/rst/directives.txt 2023-06-27 20:04:02 UTC (rev 9413)
+++ trunk/docutils/docs/ref/rst/directives.txt 2023-06-27 20:04:16 UTC (rev 9414)
@@ -884,7 +884,7 @@
The character used to separate data fields.
The special values "tab" and "space" are converted to the respective
whitespace characters. [#tab-expansion]_
- Defaults to ``,`` (comma).
+ Defaults to "``,``" (comma).
``encoding`` : encoding_
The text encoding of the external CSV data (file or URL).
@@ -909,13 +909,8 @@
``header`` : text_ (CSV data)
Supplemental data for the table header, added independently of and
before any ``header-rows`` from the main CSV data. Must use the
- same CSV format as the main CSV data.
+ same CSV format as the main CSV data. [#]_
- .. Important:: Currently, the header option uses a hard-coded CSV
- dialect with the backslash as escape character (interfering with
- the reStructuredText `escaping mechanism`_). This will change to
- the documented behaviour in Docutils 0.21.
-
``header-rows`` : integer_
The number of rows of CSV data to use in the table header.
Defaults to 0.
@@ -962,6 +957,9 @@
external files because hard tabs the directive content are
`converted to spaces`__ before it reaches the CVS reader.
+.. [#] Before Docutils 0.21, the header option used a hard-coded
+ CSV dialect with the backslash as escape character.
+
__ restructuredtext.html#whitespace
Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/tables.py 2023-06-27 20:04:02 UTC (rev 9413)
+++ trunk/docutils/docutils/parsers/rst/directives/tables.py 2023-06-27 20:04:16 UTC (rev 9414)
@@ -54,25 +54,6 @@
messages = []
return title, messages
- def process_header_option(self):
- # Provisional
- # * Will move to CSVTable in Docutils 0.21
- # as it calls `self.HeaderDialect()` only defined in CSVTable.
- # * Will change to use the same CSV dialect as the body to get in line
- # with the specification in ref/rst/directives.txt in Docutils 0.21.
- source = self.state_machine.get_source(self.lineno - 1)
- table_head = []
- max_header_cols = 0
- if 'header' in self.options: # separate table header in option
- with warnings.catch_warnings():
- warnings.simplefilter('ignore')
- header_dialect = self.HeaderDialect()
- rows, max_header_cols = self.parse_csv_data_into_rows(
- self.options['header'].split('\n'), header_dialect,
- source)
- table_head.extend(rows)
- return table_head, max_header_cols
-
def check_table_dimensions(self, rows, header_rows, stub_columns):
if len(rows) < header_rows:
error = self.reporter.error('%s header row(s) specified but '
@@ -248,7 +229,7 @@
# did not mention a rationale (part of the discussion was in private
# mail).
# This is in conflict with the documentation, which always said:
- # ""
+ # "Must use the same CSV format as the main CSV data."
# and did not change in this aspect.
#
# Maybe it was intended to have similar escape rules for rST and CSV,
@@ -278,6 +259,18 @@
' and will be removed in Docutils 0.22.',
DeprecationWarning, stacklevel=2)
+ def process_header_option(self):
+ source = self.state_machine.get_source(self.lineno - 1)
+ table_head = []
+ max_header_cols = 0
+ if 'header' in self.options: # separate table header in option
+ rows, max_header_cols = self.parse_csv_data_into_rows(
+ self.options['header'].split('\n'),
+ self.DocutilsDialect(self.options),
+ source)
+ table_head.extend(rows)
+ return table_head, max_header_cols
+
def run(self):
try:
if (not self.state.document.settings.file_insertion_enabled
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 2023-06-27 20:04:02 UTC (rev 9413)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py 2023-06-27 20:04:16 UTC (rev 9414)
@@ -29,6 +29,9 @@
class ParserTestCase(unittest.TestCase):
+
+ maxDiff = None
+
def test_parser(self):
parser = Parser()
settings = get_default_settings(Parser)
@@ -40,7 +43,7 @@
document = new_document('test data', settings.copy())
parser.parse(case_input, document)
output = document.pformat()
- self.assertEqual(output, case_expected)
+ self.assertEqual(case_expected, output)
mydir = os.path.join(TEST_ROOT, 'test_parsers/test_rst/test_directives')
@@ -555,10 +558,11 @@
"""],
["""\
.. csv-table:: inline with separate header
- :header: "Treat", Quantity, "Description"
+ :delim: space
+ :header: "Treat" Quantity "Description"
:widths: 10,20,30
- "Albatross", 2.99, "On a stick!"
+ "Albatross" 2.99 "On a stick!"
""",
"""\
<document source="test data">
@@ -1094,7 +1098,7 @@
["""\
.. csv-table:: bad CSV data
- "bad", \"csv, data
+ "bad", "csv, data
""",
"""\
<document source="test data">
@@ -1109,7 +1113,7 @@
""" % csv_eod_error_str],
["""\
.. csv-table:: bad CSV header data
- :header: "bad", \"csv, data
+ :header: "bad", "csv, data
good, csv, data
""",
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|