Skip to content

Commit aa81d6d

Browse files
committed
Add buttons for revealing and hiding all tables in an AbsoluteReport section.
1 parent d219170 commit aa81d6d

3 files changed

Lines changed: 72 additions & 1 deletion

File tree

docs/news.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
next (unreleased)
5+
-----------------
6+
7+
Downward Lab
8+
^^^
9+
* Add buttons for revealing and hiding all tables in an AbsoluteReport section (Jendrik Seipp).
10+
11+
412
v8.8 (2026-01-17)
513
-----------------
614

downward/reports/absolute.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from downward import outcomes
55
from downward.reports import PlanningReport
66
from lab import reports
7+
from lab.reports import markup
78

89

910
class AbsoluteReport(PlanningReport):
@@ -131,7 +132,17 @@ def get_markup(self):
131132

132133
toc_lines.append(f"- **[''{attribute}'' #{attribute}]**")
133134
toc_lines.append(" - " + " ".join(toc_line))
134-
sections.append((attribute, "\n".join(parts)))
135+
136+
# Add show/hide all buttons for HTML output
137+
section_content = "\n".join(parts)
138+
if self.output_format == "html" and len(tables) > 1:
139+
buttons = (
140+
f"{markup.ESCAPE_SHOW_ALL_BUTTON}{{{attribute}}} "
141+
f"{markup.ESCAPE_HIDE_ALL_BUTTON}{{{attribute}}}\n\n"
142+
)
143+
section_content = buttons + section_content
144+
145+
sections.append((attribute, section_content))
135146

136147
# Add summary before main content. This is done after creating the main content
137148
# because the summary table is extracted from all other tables.

lab/reports/markup.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
ESCAPE_WORDBREAK = "xWBRx"
77
ESCAPE_WHITESPACE = "xWHITESPACEx"
8+
ESCAPE_SHOW_ALL_BUTTON = "xSHOWALLBUTTONx"
9+
ESCAPE_HIDE_ALL_BUTTON = "xHIDEALLBUTTONx"
810

911
CSS = """\
1012
<style type="text/css">
@@ -62,6 +64,36 @@
6264
toggle_button.innerHTML = "Hide table";
6365
}
6466
67+
function show_all_tables_in_section(section_id) {
68+
var section = document.getElementById(section_id);
69+
if (!section) return;
70+
71+
var tables = section.getElementsByTagName('table');
72+
var buttons = section.getElementsByClassName('toggle-table');
73+
74+
for (var i = 0; i < tables.length; i++) {
75+
tables[i].style.display = "";
76+
}
77+
for (var i = 0; i < buttons.length; i++) {
78+
buttons[i].innerHTML = "Hide table";
79+
}
80+
}
81+
82+
function hide_all_tables_in_section(section_id) {
83+
var section = document.getElementById(section_id);
84+
if (!section) return;
85+
86+
var tables = section.getElementsByTagName('table');
87+
var buttons = section.getElementsByClassName('toggle-table');
88+
89+
for (var i = 0; i < tables.length; i++) {
90+
tables[i].style.display = "none";
91+
}
92+
for (var i = 0; i < buttons.length; i++) {
93+
buttons[i].innerHTML = "Show table";
94+
}
95+
}
96+
6597
function show_main_tables() {
6698
var names = ["unexplained-errors", "info", "summary"];
6799
for (var i = 0; i < names.length; i++) {
@@ -123,6 +155,24 @@ def _get_config(target):
123155

124156
config["postproc"].append([ESCAPE_WHITESPACE, r"&nbsp;"])
125157

158+
# Replace escaped show/hide all button markers with actual HTML
159+
config["postproc"].append(
160+
[
161+
ESCAPE_SHOW_ALL_BUTTON + r"\{(.+?)\}",
162+
r'<button type="button" onclick="show_all_tables_in_section('
163+
r"'\1')"
164+
r'">Show all tables</button>',
165+
]
166+
)
167+
config["postproc"].append(
168+
[
169+
ESCAPE_HIDE_ALL_BUTTON + r"\{(.+?)\}",
170+
r'<button type="button" onclick="hide_all_tables_in_section('
171+
r"'\1')"
172+
r'">Hide all tables</button>',
173+
]
174+
)
175+
126176
# Hide tables by default.
127177
config["postproc"].append(
128178
[
@@ -193,6 +243,8 @@ def _get_config(target):
193243
config["postproc"].append([r"BEGINCOLOR(.*?)SEP(.*?)ENDCOLOR", r"\1"])
194244
config["postproc"].append([ESCAPE_WORDBREAK, r""])
195245
config["postproc"].append([ESCAPE_WHITESPACE, r" "])
246+
config["postproc"].append([ESCAPE_SHOW_ALL_BUTTON + r"\{.+?\}", r""])
247+
config["postproc"].append([ESCAPE_HIDE_ALL_BUTTON + r"\{.+?\}", r""])
196248

197249
return config
198250

0 commit comments

Comments
 (0)