Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook for checking double quotes in title of bib entries #119

Open
SubtleMuffin opened this issue Aug 24, 2023 · 0 comments
Open

Hook for checking double quotes in title of bib entries #119

SubtleMuffin opened this issue Aug 24, 2023 · 0 comments

Comments

@SubtleMuffin
Copy link

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant