Skip to content

Commit

Permalink
Merge pull request #6 from MaximumFX/dev
Browse files Browse the repository at this point in the history
Added text sanitation for tables
  • Loading branch information
MaximumFX authored Apr 10, 2024
2 parents 142e672 + 58e3650 commit 1845663
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tk-readme-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@


def table(cols: list[str], rows: list[list[str]]) -> str:
def sanitize(content: str):
if content is None:
return ""
return content.strip().replace("\n", "<br>").replace("|", "\\|")

sizes = list(map(len, cols))
for row in rows:
for i, item in enumerate(row):
item = item.strip()
item = sanitize(item)
if len(item) > sizes[i]:
sizes[i] = len(item)

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

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

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

Expand Down Expand Up @@ -197,6 +204,7 @@ def table(cols: list[str], rows: list[list[str]]) -> str:
"shotgun_entity_type": "ShotGrid entity types",
"shotgun_permission_group": "ShotGrid permission groups",
"shotgun_filter": "ShotGrid filters",
"tank_type": "Tank types",
}
if "configuration" in info and info["configuration"] is not None:
readme += "## Configuration\n\n"
Expand Down Expand Up @@ -245,6 +253,7 @@ def table(cols: list[str], rows: list[list[str]]) -> str:
value,
)
)
print(cols, rows)
readme += table(cols, rows)
readme += "\n"

Expand Down

0 comments on commit 1845663

Please sign in to comment.