|
From: <mi...@us...> - 2022-02-19 23:32:45
|
Revision: 9009
http://sourceforge.net/p/docutils/code/9009
Author: milde
Date: 2022-02-19 23:32:41 +0000 (Sat, 19 Feb 2022)
Log Message:
-----------
Write table column widths with 3 digits precision. Fixes bug #444.
Bug #444 reports visible effects of rounding errors with the current
rounding to integer percentages (e.g. 7 columns 13% and one 9% for
8 columns of equal width).
Allow a fractional part (1 digit) when table column widths are
written as percentages in the "colgroup".
Use f-string literal to format coefficient as percentage.
CSS allows decimal numbers (since CSS1) in the specification
of percentages.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/writers/_html_base.py
trunk/docutils/test/functional/expected/standalone_rst_html5.html
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2022-02-11 14:47:51 UTC (rev 9008)
+++ trunk/docutils/HISTORY.txt 2022-02-19 23:32:41 UTC (rev 9009)
@@ -66,6 +66,7 @@
* docutils/writers/_html_base.py
- Add 'html writers' to `config_section_dependencies`. Fixes bug #443.
+ - Write table column widths with 3 digits precision. Fixes bug #444.
* docutils/writers/pep_html/
Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py 2022-02-11 14:47:51 UTC (rev 9008)
+++ trunk/docutils/docutils/writers/_html_base.py 2022-02-19 23:32:41 UTC (rev 9009)
@@ -679,12 +679,12 @@
'colwidths-grid' not in self.settings.table_style
and 'colwidths-given' not in node.parent.parent['classes']):
return
+ self.body.append(self.starttag(node, 'colgroup'))
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)
+ colwidth = node['colwidth'] / total_width
self.body.append(self.emptytag(node, 'col',
- style='width: %i%%' % colwidth))
+ style=f'width: {colwidth:.1%}'))
self.body.append('</colgroup>\n')
def visit_comment(self, node,
Modified: trunk/docutils/test/functional/expected/standalone_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html5.html 2022-02-11 14:47:51 UTC (rev 9008)
+++ trunk/docutils/test/functional/expected/standalone_rst_html5.html 2022-02-19 23:32:41 UTC (rev 9009)
@@ -1169,9 +1169,9 @@
<table class="test" style="width: 95%;">
<caption>list table with integral header</caption>
<colgroup>
-<col style="width: 26%" />
-<col style="width: 21%" />
-<col style="width: 53%" />
+<col style="width: 26.3%" />
+<col style="width: 21.1%" />
+<col style="width: 52.6%" />
</colgroup>
<thead>
<tr><th class="head stub"><p>Treat</p></th>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|