With Slurm 23.X there is expanded usage of JSON output for common sacct/scontrol commands. This will greatly simplify the generation of the partition tables.
This could also be combined with other libraries (like pandas' df.to_markdown) to further simplify the code.