Skip to content

Commit ed98d2d

Browse files
committed
feat
1 parent 275dac7 commit ed98d2d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

capitalized_keywords.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@ def process_markdown_file(file_path):
5252

5353
# Replace the front matter in the content
5454
updated_front_matter = yaml.dump(front_matter_dict, default_flow_style=False)
55-
updated_content = re.sub(r'---(.*?)---', f'---\n{updated_front_matter}---', content, flags=re.DOTALL)
55+
56+
# Escape backslashes in YAML to avoid issues with re.sub
57+
updated_front_matter = re.escape(updated_front_matter)
58+
59+
# Rebuild the full content with updated front matter, use re.sub for replacement
60+
updated_content = re.sub(r'---(.*?)---', f'---\n{updated_front_matter}\n---', content, flags=re.DOTALL)
61+
62+
# Unescape YAML content for the final write back
63+
updated_content = updated_content.replace(r'\n', '\n').replace(r'\\', '\\')
5664

5765
# Save the updated content back to the file
5866
with open(file_path, 'w', encoding='utf-8') as file:

0 commit comments

Comments
 (0)