Skip to content

Commit 6e5ad80

Browse files
committed
fix bug with rendering backslashes
1 parent bf9b21e commit 6e5ad80

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

scripts/hooks.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,9 @@ def _create_markdown_link(attribute: str, model: str) -> str:
4242
return f"[{attribute}]({link_prefix}-{slug})"
4343

4444

45-
def _escape_backslashes(text: str) -> str:
46-
"""Escape backslashes for proper markdown rendering."""
47-
return text.replace(r"\\", r"\\\\")
48-
49-
50-
def _format_validation_rules(rules: str) -> str:
45+
def _format_validation_rules(col: pd.Series) -> pd.Series:
5146
"""Format validation rules, replacing empty strings with '_None_'."""
52-
return _escape_backslashes(rules) if rules else "_None_"
47+
return col.str.replace(r"\\", r"\\\\", regex=True).replace("", "_None_")
5348

5449

5550
# --- Core logic functions ---
@@ -70,13 +65,15 @@ def generate_linked_table(model: str):
7065
examples_df = pd.read_csv(example_file, quoting=1).fillna("")
7166

7267
# First select only the columns we want from annotation_df
73-
df = annotation_df[[
74-
"Attribute",
75-
"Description",
76-
"Required",
77-
"Validation Rules",
78-
"Valid Values",
79-
]]
68+
df = annotation_df[
69+
[
70+
"Attribute",
71+
"Description",
72+
"Required",
73+
"Validation Rules",
74+
"Valid Values",
75+
]
76+
]
8077

8178
# Then add the Example column and rename it to Examples
8279
df = df.merge(
@@ -97,16 +94,17 @@ def generate_linked_table(model: str):
9794

9895
# Fix any remaining rendering issues, such as escaping backslashes.
9996
# then output table as CSV.
100-
df["Validation Rules"] = df["Validation Rules"].apply(_format_validation_rules)
97+
df["Validation Rules"] = _format_validation_rules(df["Validation Rules"])
10198
df[COLS_TO_RENDER].to_csv(reference_file, index=False)
10299

103100

104101
def generate_valid_values_markdown(model: str):
105102
"""Generate docs page for standard terms of the given data model."""
106103
dest_parent_dir = join("docs", "valid_values")
107104

108-
with open(join("modules", MAPPING_FILENAME)) as f, \
109-
open(join(dest_parent_dir, f"{model}.md"), "w") as md:
105+
with open(join("modules", MAPPING_FILENAME)) as f, open(
106+
join(dest_parent_dir, f"{model}.md"), "w"
107+
) as md:
110108
mapping = yaml.safe_load(f)
111109

112110
# Create a section in the docs page for each attribute that has a list

0 commit comments

Comments
 (0)