-
-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Hi @jonasbb, great work! I wrote myself a hook that check and replace single parentheses with double parentheses in bib files. Here are the related scripts:
- repo: local
hooks:
- id: double-parentheses
name: Replace single parentheses with double parentheses
description: Replace single parentheses with double parentheses in title entry of bib files
entry: ./double_parentheses_hook.py
language: python
files: '\.bib$'
and the corresponding Python file
#!/usr/bin/env python3
import sys
import re
def main():
try:
file_path = sys.argv[1]
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# Modify the regular expression as needed
updated_content = re.sub(r'\btitle\s*=\s*{([^{}]+)}', r'title = {{\1}}', content)
with open(file_path, 'w', encoding='utf-8') as file:
file.write(updated_content)
sys.exit(0)
except Exception as e:
print("Error:", e)
sys.exit(1)
if __name__ == '__main__':
main()
If you think this is beneficial, feel free to add to this repo :)
Metadata
Metadata
Assignees
Labels
No labels