Skip to content
Closed
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
118 changes: 62 additions & 56 deletions yaml_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ def linkify_cell(value):

def repl(m):
url = m.group(1)
href = url if url.lower().startswith(("http://", "https://")) else f"https://{url}"
href = (
url if url.lower().startswith(("http://", "https://")) else f"https://{url}"
)
return f'<a href="{href}">{url}</a>'

return URL_RE.sub(repl, value)


yaml_file = "problems.yaml"

html_dir = "docs/"
Expand All @@ -31,9 +34,6 @@ def repl(m):
html_index = f"{html_dir}index.html"
html_table_template = f"{html_dir}table_template.html"

# Load data
with open(yaml_file) as yaml_input:
data = pd.json_normalize(yaml.safe_load(yaml_input))

# Choose desired columns
all_columns = False
Expand All @@ -51,55 +51,61 @@ def repl(m):
"reference",
"implementation"]

if all_columns is False:
columns = default_columns
data = data[columns]

data = data.map(linkify_cell)

# Generate plain table
table = data.to_html(render_links=False,
escape=False, # Don't escape HTML in cells (to allow links)
index=False,
table_id="problems",
classes=["display compact", "display", "styled-table"], # Set display style
border=0,
na_rep="") # Leave NaN cells empty

# Add footer to facilitate individual column search
idx = table.index('</table>')
final_table = table[:idx] + "<tfoot><tr>" + " ".join(["<th>"+ i +"</th>" for i in data.columns])+"</tr> </tfoot>" + table[idx:]

default_hidden_columns = {"textual description", "reference", "implementation"}

column_toggles = "".join(
[
(
f'<label class="column-chip">'
f'<input class="col-toggle" type="checkbox" data-column="{i}"'
f'{" checked" if col not in default_hidden_columns else ""}>'
f'<span>{escape(col)}</span>'
f'</label>'
)
for i, col in enumerate(data.columns)
]
)

with open(html_table_template, encoding="utf-8") as template_file:
table_template = template_file.read()

table_markup = (
table_template
.replace("__COLUMN_TOGGLES__", column_toggles)
.replace("__TABLE__", final_table)
)

# Write table to file
with open(html_table, "w", encoding="utf-8") as table_file:
table_file.write(table_markup)

# Merge table and scripts into HTML page
with open(html_index, "wb") as output_file:
for part_path in [html_header, html_table, html_scripts, html_footer]:
with open(part_path, "rb") as part_file:
shutil.copyfileobj(part_file, output_file)
if __name__ == "__main__":
# Load data
with open(yaml_file) as yaml_input:
Comment thread
CIGbalance marked this conversation as resolved.
data = pd.json_normalize(yaml.safe_load(yaml_input))


Comment on lines +58 to +59
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple consecutive blank lines/whitespace-only lines after loading the YAML (between the with open(...) block and the next if), which adds noise in the main flow. Please remove the extra blank lines to keep the script compact and consistent with the surrounding style.

Suggested change

Copilot uses AI. Check for mistakes.
if all_columns is False:
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within this block, if all_columns is False: is a non-idiomatic boolean check and reduces readability. Prefer if not all_columns: (or just if all_columns: where appropriate) for consistency with typical Python style.

Suggested change
if all_columns is False:
if not all_columns:

Copilot uses AI. Check for mistakes.
columns = default_columns
data = data[columns]

data = data.map(linkify_cell)

# Generate plain table
table = data.to_html(render_links=False,
escape=False, # Don't escape HTML in cells (to allow links)
index=False,
table_id="problems",
classes=["display compact", "display", "styled-table"], # Set display style
border=0,
na_rep="") # Leave NaN cells empty

# Add footer to facilitate individual column search
idx = table.index('</table>')
final_table = table[:idx] + "<tfoot><tr>" + " ".join(["<th>"+ i +"</th>" for i in data.columns])+"</tr> </tfoot>" + table[idx:]

default_hidden_columns = {"textual description", "reference", "implementation"}

column_toggles = "".join(
[
(
f'<label class="column-chip">'
f'<input class="col-toggle" type="checkbox" data-column="{i}"'
f'{" checked" if col not in default_hidden_columns else ""}>'
f'<span>{escape(col)}</span>'
f'</label>'
)
for i, col in enumerate(data.columns)
]
)

with open(html_table_template, encoding="utf-8") as template_file:
table_template = template_file.read()

table_markup = (
table_template
.replace("__COLUMN_TOGGLES__", column_toggles)
.replace("__TABLE__", final_table)
)

# Write table to file
with open(html_table, "w", encoding="utf-8") as table_file:
table_file.write(table_markup)

# Merge table and scripts into HTML page
with open(html_index, "wb") as output_file:
for part_path in [html_header, html_table, html_scripts, html_footer]:
with open(part_path, "rb") as part_file:
shutil.copyfileobj(part_file, output_file)
Comment thread
CIGbalance marked this conversation as resolved.