diff options
| author | Shulhan <m.shulhan@gmail.com> | 2020-12-05 18:02:24 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2020-12-05 18:02:48 +0700 |
| commit | 755d65c0d6faa0f89b857cfde97f270ef47effb7 (patch) | |
| tree | f19b2d890310dc2034d84dd0a74e84e826fb7b14 | |
| parent | 5e86e9517d147874d35311b4eff9a1a3714b31e1 (diff) | |
| download | asciidoctor-go-755d65c0d6faa0f89b857cfde97f270ef47effb7.tar.xz | |
all: fix table width calculation
If we have three columns, the first and second column width are
100/3 = 33.3333
but the last column should be 100 - (33.3333+33.3333) = 33.3334.
| -rw-r--r-- | adoc_node_test.go | 2 | ||||
| -rw-r--r-- | adoc_table.go | 11 | ||||
| -rw-r--r-- | testdata/got.test.html | 26 |
3 files changed, 23 insertions, 16 deletions
diff --git a/adoc_node_test.go b/adoc_node_test.go index 95df8fd..59ef18d 100644 --- a/adoc_node_test.go +++ b/adoc_node_test.go @@ -162,7 +162,7 @@ func TestAdocNode_postConsumeTable(t *testing.T) { classNameValignTop, }, }, { - width: big.NewRat("33.3333"), + width: big.NewRat("33.3334"), classes: []string{ classNameTableBlock, classNameHalignLeft, diff --git a/adoc_table.go b/adoc_table.go index c063a5c..d7271cb 100644 --- a/adoc_table.go +++ b/adoc_table.go @@ -195,6 +195,7 @@ func (table *adocTable) parseOptions(opts []string) { func (table *adocTable) recalculateWidth() { var ( totalWidth = big.NewRat(0) + lastWidth = big.NewRat(100) hasAutowidth bool ) for _, format := range table.formats { @@ -205,9 +206,15 @@ func (table *adocTable) recalculateWidth() { totalWidth.Add(format.width) } } - for _, format := range table.formats { - if !hasAutowidth { + for x, format := range table.formats { + if hasAutowidth { + continue + } + if x == len(table.formats)-1 { + format.width = lastWidth + } else { format.width = big.QuoRat(format.width, totalWidth).Mul(100) + lastWidth.Sub(format.width) } } } diff --git a/testdata/got.test.html b/testdata/got.test.html index dbd4b3f..2ec79f4 100644 --- a/testdata/got.test.html +++ b/testdata/got.test.html @@ -1390,7 +1390,7 @@ D</p></td> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> -<col style="width: 33.3333%;"> +<col style="width: 33.3334%;"> </colgroup> <tbody> <tr> @@ -1481,7 +1481,7 @@ D</p></td> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> -<col style="width: 33.3333%;"> +<col style="width: 33.3334%;"> </colgroup> <tbody> <tr> @@ -1508,7 +1508,7 @@ D</p></td> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> -<col style="width: 33.3333%;"> +<col style="width: 33.3334%;"> </colgroup> <tbody> <tr> @@ -1682,7 +1682,7 @@ D</p></td> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> -<col style="width: 33.3333%;"> +<col style="width: 33.3334%;"> </colgroup> <thead> <tr> @@ -1703,7 +1703,7 @@ D</p></td> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> -<col style="width: 33.3333%;"> +<col style="width: 33.3334%;"> </colgroup> <thead> <tr> @@ -1724,7 +1724,7 @@ D</p></td> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> -<col style="width: 33.3333%;"> +<col style="width: 33.3334%;"> </colgroup> <thead> <tr> @@ -1748,7 +1748,7 @@ D</p></td> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> -<col style="width: 33.3333%;"> +<col style="width: 33.3334%;"> </colgroup> <thead> <tr> @@ -1769,7 +1769,7 @@ D</p></td> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> -<col style="width: 33.3333%;"> +<col style="width: 33.3334%;"> </colgroup> <thead> <tr> @@ -1790,7 +1790,7 @@ D</p></td> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> -<col style="width: 33.3333%;"> +<col style="width: 33.3334%;"> </colgroup> <thead> <tr> @@ -1815,7 +1815,7 @@ D</p></td> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> -<col style="width: 33.3333%;"> +<col style="width: 33.3334%;"> </colgroup> <thead> <tr> @@ -1841,7 +1841,7 @@ D</p></td> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> -<col style="width: 33.3333%;"> +<col style="width: 33.3334%;"> </colgroup> <thead> <tr> @@ -1867,7 +1867,7 @@ D</p></td> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> -<col style="width: 33.3333%;"> +<col style="width: 33.3334%;"> </colgroup> <thead> <tr> @@ -1893,7 +1893,7 @@ D</p></td> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> -<col style="width: 33.3333%;"> +<col style="width: 33.3334%;"> </colgroup> <thead> <tr> |
