Skip to content

Commit

Permalink
Merge pull request #5 from MaximumFX/dev
Browse files Browse the repository at this point in the history
Added whitespace stripping to tables
  • Loading branch information
MaximumFX authored Apr 10, 2024
2 parents 9219f36 + c4f10f2 commit 142e672
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tk-readme-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ def table(cols: list[str], rows: list[list[str]]) -> str:
sizes = list(map(len, cols))
for row in rows:
for i, item in enumerate(row):
item = item.strip()
if len(item) > sizes[i]:
sizes[i] = len(item)

table_md = ""
for i, col in enumerate(cols):
table_md += f"| {col}{' ' * (sizes[i] - len(col) + 1)}"
table_md += f"| {col.strip()}{' ' * (sizes[i] - len(col.strip()) + 1)}"
table_md += "|\n"

for i, col in enumerate(cols):
Expand All @@ -21,7 +22,7 @@ def table(cols: list[str], rows: list[list[str]]) -> str:

for row in rows:
for i, item in enumerate(row):
table_md += f"| {item}{' ' * (sizes[i] - len(item) + 1)}"
table_md += f"| {item.strip()}{' ' * (sizes[i] - len(item.strip()) + 1)}"
table_md += "|\n"
return table_md + "\n"

Expand Down

0 comments on commit 142e672

Please sign in to comment.