From 79b93f97664bf1dcb9cd1d13739edf5c65c9cbe0 Mon Sep 17 00:00:00 2001 From: MaximumFX Date: Wed, 10 Apr 2024 19:23:46 +0200 Subject: [PATCH 1/2] Added text sanitation for tables --- tk-readme-generator.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tk-readme-generator.py b/tk-readme-generator.py index eddb1c2..29a92c4 100644 --- a/tk-readme-generator.py +++ b/tk-readme-generator.py @@ -4,16 +4,19 @@ def table(cols: list[str], rows: list[list[str]]) -> str: + def sanitize(content: str): + return content.strip().replace("\n", "
").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)}" + table_md += f"| {sanitize(col)}{' ' * (sizes[i] - len(sanitize(col)) + 1)}" table_md += "|\n" for i, col in enumerate(cols): @@ -22,7 +25,9 @@ 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)}" + table_md += ( + f"| {sanitize(item)}{' ' * (sizes[i] - len(sanitize(item)) + 1)}" + ) table_md += "|\n" return table_md + "\n" @@ -197,6 +202,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" @@ -245,6 +251,7 @@ def table(cols: list[str], rows: list[list[str]]) -> str: value, ) ) + print(cols, rows) readme += table(cols, rows) readme += "\n" From 58e3650ad414aced1e4a3d97271f708f07555dff Mon Sep 17 00:00:00 2001 From: MaximumFX Date: Wed, 10 Apr 2024 19:26:34 +0200 Subject: [PATCH 2/2] Updated text sanitation for tables --- tk-readme-generator.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tk-readme-generator.py b/tk-readme-generator.py index 29a92c4..9702fae 100644 --- a/tk-readme-generator.py +++ b/tk-readme-generator.py @@ -5,7 +5,9 @@ def table(cols: list[str], rows: list[list[str]]) -> str: def sanitize(content: str): - return content.strip().replace("\n", "
").replace("|", "\|") + if content is None: + return "" + return content.strip().replace("\n", "
").replace("|", "\\|") sizes = list(map(len, cols)) for row in rows: @@ -16,7 +18,8 @@ def sanitize(content: str): table_md = "" for i, col in enumerate(cols): - table_md += f"| {sanitize(col)}{' ' * (sizes[i] - len(sanitize(col)) + 1)}" + content = sanitize(col) + table_md += f"| {content}{' ' * (sizes[i] - len(content) + 1)}" table_md += "|\n" for i, col in enumerate(cols): @@ -25,9 +28,8 @@ def sanitize(content: str): for row in rows: for i, item in enumerate(row): - table_md += ( - f"| {sanitize(item)}{' ' * (sizes[i] - len(sanitize(item)) + 1)}" - ) + content = sanitize(item) + table_md += f"| {content}{' ' * (sizes[i] - len(content) + 1)}" table_md += "|\n" return table_md + "\n"