Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/spec/tables/csv-table-auto-keyword.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. csv-table:: Frozen Delights!
:header: "Treat", "Quantity", "Description"
:widths: auto

"Albatross", 2.99, "On a stick!"
"Crunchy Frog", 1.49, "If we took the bones out,
it wouldn't be crunchy, now would it?"
"Gannet Ripple", 1.99, "On a stick!"
21 changes: 21 additions & 0 deletions docs/spec/tables/csv-table-auto-keyword.typ.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#figure([
#table(
columns: 3,
table.header(
[Treat],
[Quantity],
[Description],
),
[Albatross],
[2.99],
[On a stick!],
[Crunchy Frog],
[1.49],
[If we took the bones out,
it wouldn't be crunchy, now would it?],
[Gannet Ripple],
[1.99],
[On a stick!],
)],
caption: [Frozen Delights!],
)
7 changes: 7 additions & 0 deletions docs/spec/tables/csv-table-autolayout.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. csv-table:: Frozen Delights!
:header: "Treat", "Quantity", "Description"

"Albatross", 2.99, "On a stick!"
"Crunchy Frog", 1.49, "If we took the bones out,
it wouldn't be crunchy, now would it?"
"Gannet Ripple", 1.99, "On a stick!"
21 changes: 21 additions & 0 deletions docs/spec/tables/csv-table-autolayout.typ.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#figure([
#table(
columns: 3,
table.header(
[Treat],
[Quantity],
[Description],
),
[Albatross],
[2.99],
[On a stick!],
[Crunchy Frog],
[1.49],
[If we took the bones out,
it wouldn't be crunchy, now would it?],
[Gannet Ripple],
[1.99],
[On a stick!],
)],
caption: [Frozen Delights!],
)
14 changes: 14 additions & 0 deletions docs/spec/tables/grid-table-with-widths.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. table:: Truth table with grid-derived widths
:widths: grid

+-------+-------+-----------+
| A | B | A and B |
+=======+=======+===========+
| False | False | False |
+-------+-------+-----------+
| True | False | False |
+-------+-------+-----------+
| False | True | False |
+-------+-------+-----------+
| True | True | True |
+-------+-------+-----------+
23 changes: 23 additions & 0 deletions docs/spec/tables/grid-table-with-widths.typ.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#figure([
#table(
columns: (7fr, 7fr, 11fr),
table.header(
[A],
[B],
[A and B],
),
[False],
[False],
[False],
[True],
[False],
[False],
[False],
[True],
[False],
[True],
[True],
[True],
)],
caption: [Truth table with grid-derived widths],
)
2 changes: 1 addition & 1 deletion docs/spec/tables/grid-table.typ.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#table(
columns: (24fr, 12fr, 10fr, 10fr),
columns: 4,
table.header(
[Header row, column 1
(header rows optional)],
Expand Down
66 changes: 66 additions & 0 deletions docs/spec/tables/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,72 @@ List table
.. literalinclude:: list-table.typ.txt
:language: typst

List table with autolayout
--------------------------

.. tab-set-code::

.. literalinclude:: list-table-autolayout.rst.txt
:language: rst

.. literalinclude:: list-table-autolayout.typ.txt
:language: typst

CSV table with autolayout
-------------------------

.. tab-set-code::

.. literalinclude:: csv-table-autolayout.rst.txt
:language: rst

.. literalinclude:: csv-table-autolayout.typ.txt
:language: typst

CSV table with "auto" keyword
-----------------------------

.. tab-set-code::

.. literalinclude:: csv-table-auto-keyword.rst.txt
:language: rst

.. literalinclude:: csv-table-auto-keyword.typ.txt
:language: typst

List table with "auto" keyword
------------------------------

.. tab-set-code::

.. literalinclude:: list-table-auto-keyword.rst.txt
:language: rst

.. literalinclude:: list-table-auto-keyword.typ.txt
:language: typst

Simple table with explicit widths
---------------------------------

.. tab-set-code::

.. literalinclude:: simple-table-with-widths.rst.txt
:language: rst

.. literalinclude:: simple-table-with-widths.typ.txt
:language: typst

Grid table with "grid" widths keyword
-------------------------------------

.. tab-set-code::

.. literalinclude:: grid-table-with-widths.rst.txt
:language: rst

.. literalinclude:: grid-table-with-widths.typ.txt
:language: typst

References
==========

Expand Down
17 changes: 17 additions & 0 deletions docs/spec/tables/list-table-auto-keyword.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. list-table:: Frozen Delights!
:widths: auto
:header-rows: 1

* - Treat
- Quantity
- Description
* - Albatross
- 2.99
- On a stick!
* - Crunchy Frog
- 1.49
- If we took the bones out, it wouldn't be
crunchy, now would it?
* - Gannet Ripple
- 1.99
- On a stick!
21 changes: 21 additions & 0 deletions docs/spec/tables/list-table-auto-keyword.typ.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#figure([
#table(
columns: 3,
table.header(
[Treat],
[Quantity],
[Description],
),
[Albatross],
[2.99],
[On a stick!],
[Crunchy Frog],
[1.49],
[If we took the bones out, it wouldn't be
crunchy, now would it?],
[Gannet Ripple],
[1.99],
[On a stick!],
)],
caption: [Frozen Delights!],
)
16 changes: 16 additions & 0 deletions docs/spec/tables/list-table-autolayout.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. list-table:: Frozen Delights!
:header-rows: 1

* - Treat
- Quantity
- Description
* - Albatross
- 2.99
- On a stick!
* - Crunchy Frog
- 1.49
- If we took the bones out, it wouldn't be
crunchy, now would it?
* - Gannet Ripple
- 1.99
- On a stick!
21 changes: 21 additions & 0 deletions docs/spec/tables/list-table-autolayout.typ.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#figure([
#table(
columns: 3,
table.header(
[Treat],
[Quantity],
[Description],
),
[Albatross],
[2.99],
[On a stick!],
[Crunchy Frog],
[1.49],
[If we took the bones out, it wouldn't be
crunchy, now would it?],
[Gannet Ripple],
[1.99],
[On a stick!],
)],
caption: [Frozen Delights!],
)
11 changes: 11 additions & 0 deletions docs/spec/tables/simple-table-with-widths.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.. table:: Truth table with explicit widths
:widths: 10 10 15

===== ===== =======
A B A and B
===== ===== =======
False False False
True False False
False True False
True True True
===== ===== =======
23 changes: 23 additions & 0 deletions docs/spec/tables/simple-table-with-widths.typ.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#figure([
#table(
columns: (10fr, 10fr, 15fr),
table.header(
[A],
[B],
[A and B],
),
[False],
[False],
[False],
[True],
[False],
[False],
[False],
[True],
[False],
[True],
[True],
[True],
)],
caption: [Truth table with explicit widths],
)
2 changes: 1 addition & 1 deletion docs/spec/tables/simple-table.typ.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#table(
columns: (5fr, 5fr, 7fr),
columns: 3,
table.header(
[A],
[B],
Expand Down
18 changes: 13 additions & 5 deletions src/rst2typst/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,19 @@ def depart_table(self, node: nodes.table):
self.body.append("\n")

def visit_tgroup(self, node: nodes.tgroup):
cols = [
f"{colspec['colwidth']}fr" if colspec != "auto" else "auto"
for colspec in node.findall(nodes.colspec)
]
self.body.append(f"{self._hi.indent}columns: ({', '.join(cols)}),\n")
table_node = node.parent
colwidths_given = "colwidths-given" in table_node.get("classes", [])

if colwidths_given:
# Use explicit fractional widths when the author specified them.
cols = [
f"{colspec['colwidth']}fr" for colspec in node.findall(nodes.colspec)
]
self.body.append(f"{self._hi.indent}columns: ({', '.join(cols)}),\n")
else:
# Typst defaults to columns: 1, so we must always emit the column
# count; the integer shorthand sizes all columns automatically.
self.body.append(f"{self._hi.indent}columns: {node['cols']},\n")

def depart_tgroup(self, node: nodes.tgroup):
pass
Expand Down