Skip to content

Commit 2862a8b

Browse files
authored
Custom tags (#73)
1 parent 6861ed8 commit 2862a8b

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
0.4.7 (2022-04-13)
2+
==================
3+
4+
Added
5+
-----
6+
- Additional `tags` like e.g. captions are supported (#10).
7+
18
0.4.6 (2022-03-29)
29
==================
310

docs/advanced_parameters.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jupytext:
55
extension: .md
66
format_name: myst
77
format_version: 0.13
8-
jupytext_version: 1.11.5
8+
jupytext_version: 1.13.8
99
kernelspec:
1010
display_name: itables
1111
language: python
@@ -91,6 +91,19 @@ opt.classes = ["display", "cell-border"]
9191
df
9292
```
9393

94+
## Table captions
95+
96+
You can set additional `tags` like a [caption](https://datatables.net/blog/2014-11-07) on the table with the `tags` option:
97+
98+
```{code-cell}
99+
show(df, tags='<caption>Countries from the World Bank Database</caption>')
100+
```
101+
102+
The position of the caption can be set explicitly as in the datatables example above (note that the default position may depend on how you render the notebook):
103+
```{code-cell}
104+
show(df, tags='<caption style="caption-side: top">Countries from the World Bank Database</caption>')
105+
```
106+
94107
## Float precision
95108

96109
Floats are rounded using `pd.options.display.float_format`. Please change that format according to your preference.

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dependencies:
66
- python
77
- jupyter
88
- jupyterlab
9-
- jupytext
9+
- jupytext>=1.13.8
1010
- markdown-it-py>=2.0
1111
- nbconvert
1212
- ipykernel

itables/javascript.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _formatted_values(df):
6363
return formatted_df.values.tolist()
6464

6565

66-
def _table_header(df, table_id, show_index, classes, style):
66+
def _table_header(df, table_id, show_index, classes, style, tags):
6767
"""This function returns the HTML table header. Rows are not included."""
6868
# Generate table head using pandas.to_html(), see issue 63
6969
pattern = re.compile(r".*<thead>(.*)</thead>", flags=re.MULTILINE | re.DOTALL)
@@ -80,7 +80,7 @@ def _table_header(df, table_id, show_index, classes, style):
8080
else:
8181
style = ""
8282

83-
return f'<table id="{table_id}" class="{classes}"{style}><thead>{thead}</thead><tbody>{tbody}</tbody></table>'
83+
return f'<table id="{table_id}" class="{classes}"{style}>{tags}<thead>{thead}</thead><tbody>{tbody}</tbody></table>'
8484

8585

8686
def eval_functions_dumps(obj):
@@ -124,6 +124,7 @@ def _datatables_repr_(df=None, tableId=None, **kwargs):
124124
# These options are used here, not in DataTable
125125
classes = kwargs.pop("classes")
126126
style = kwargs.pop("style")
127+
tags = kwargs.pop("tags")
127128
showIndex = kwargs.pop("showIndex")
128129
maxBytes = kwargs.pop("maxBytes", 0)
129130
maxRows = kwargs.pop("maxRows", 0)
@@ -155,7 +156,7 @@ def _datatables_repr_(df=None, tableId=None, **kwargs):
155156
if not showIndex:
156157
df = df.set_index(pd.RangeIndex(len(df.index)))
157158

158-
table_header = _table_header(df, tableId, showIndex, classes, style)
159+
table_header = _table_header(df, tableId, showIndex, classes, style, tags)
159160
output = replace_value(
160161
output,
161162
'<table id="table_id"><thead><tr><th>A</th></tr></thead></table>',

itables/options.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"""Default table style"""
1111
style = "max-width:100%"
1212

13+
"""Additional tags like e.g. caption"""
14+
tags = ""
15+
1316
"""Maximum bytes for displaying a table"""
1417
maxBytes = 2**16
1518

itables/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""ITables' version number"""
22

3-
__version__ = "0.4.6"
3+
__version__ = "0.4.7"

0 commit comments

Comments
 (0)