Added description table to the ascii output

This commit is contained in:
Nathan Schneider
2025-12-02 15:27:09 -07:00
parent 8edc0df755
commit f123db6faf
2 changed files with 96 additions and 0 deletions

View File

@@ -56,8 +56,10 @@ def generate_bicorder_text(json_data):
lines = []
# First pass: calculate maximum widths for left and right terms
# Also collect all terms for the glossary
max_left_width = 0
max_right_width = 0
glossary_terms = {} # Dictionary to store term: description mappings
# Check diagnostic gradients
for diagnostic_set in json_data.get("diagnostic", []):
@@ -67,6 +69,12 @@ def generate_bicorder_text(json_data):
max_left_width = max(max_left_width, len(term_left))
max_right_width = max(max_right_width, len(term_right))
# Collect terms for glossary
if term_left:
glossary_terms[term_left] = gradient.get("term_left_description", "")
if term_right:
glossary_terms[term_right] = gradient.get("term_right_description", "")
# Check analysis items
for analysis_item in json_data.get("analysis", []):
term_left = analysis_item.get("term_left", "")
@@ -74,6 +82,12 @@ def generate_bicorder_text(json_data):
max_left_width = max(max_left_width, len(term_left))
max_right_width = max(max_right_width, len(term_right))
# Collect terms for glossary
if term_left:
glossary_terms[term_left] = analysis_item.get("term_left_description", "")
if term_right:
glossary_terms[term_right] = analysis_item.get("term_right_description", "")
# Calculate the width needed for centering
# Gradient line format: "{left_term} < [|||||||||] > {right_term}"
# That's: max_left_width + 3 + 11 + 3 + max_right_width
@@ -136,6 +150,31 @@ def generate_bicorder_text(json_data):
lines.append("")
# Glossary section
lines.append(center_text("GLOSSARY", center_width))
lines.append("")
# Generate pandoc-compatible table
# Sort terms alphabetically (case-insensitive) for consistent output
sorted_terms = sorted(glossary_terms.items(), key=lambda x: x[0].lower())
if sorted_terms:
# Calculate column widths for the table
max_term_width = max(len(term) for term, _ in sorted_terms)
max_term_width = max(max_term_width, len("Term")) # At least as wide as header
# Build the table
# Header row
lines.append(f"| {'Term'.ljust(max_term_width)} | Description |")
# Separator row
lines.append(f"| {'-' * max_term_width} | {'-' * 11} |")
# Data rows
for term, description in sorted_terms:
lines.append(f"| {term.ljust(max_term_width)} | {description} |")
lines.append("")
return "\n".join(lines)