Skip to content

Commit 1845663

Browse files
authored
Merge pull request #6 from MaximumFX/dev
Added text sanitation for tables
2 parents 142e672 + 58e3650 commit 1845663

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tk-readme-generator.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@
44

55

66
def table(cols: list[str], rows: list[list[str]]) -> str:
7+
def sanitize(content: str):
8+
if content is None:
9+
return ""
10+
return content.strip().replace("\n", "<br>").replace("|", "\\|")
11+
712
sizes = list(map(len, cols))
813
for row in rows:
914
for i, item in enumerate(row):
10-
item = item.strip()
15+
item = sanitize(item)
1116
if len(item) > sizes[i]:
1217
sizes[i] = len(item)
1318

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

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

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

@@ -197,6 +204,7 @@ def table(cols: list[str], rows: list[list[str]]) -> str:
197204
"shotgun_entity_type": "ShotGrid entity types",
198205
"shotgun_permission_group": "ShotGrid permission groups",
199206
"shotgun_filter": "ShotGrid filters",
207+
"tank_type": "Tank types",
200208
}
201209
if "configuration" in info and info["configuration"] is not None:
202210
readme += "## Configuration\n\n"
@@ -245,6 +253,7 @@ def table(cols: list[str], rows: list[list[str]]) -> str:
245253
value,
246254
)
247255
)
256+
print(cols, rows)
248257
readme += table(cols, rows)
249258
readme += "\n"
250259

0 commit comments

Comments
 (0)