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

Enhanced handling of line breaks in pdf #127

Open
zkn365 opened this issue Sep 6, 2024 · 0 comments
Open

Enhanced handling of line breaks in pdf #127

zkn365 opened this issue Sep 6, 2024 · 0 comments

Comments

@zkn365
Copy link

zkn365 commented Sep 6, 2024

I used the following function to enhance the handling of line breaks in pdf after it converted into markdown. I hope it could be considered in the next revision, thanks!

def remove_pdf_newlines(text):
    # Convert Windows-style newlines to Unix style
    text = text.replace('\r\n', '\n')
    # Merge lines that do not end with a period, question mark, or exclamation point
    text = re.sub(r'(?<![.!?])\n(?=[a-zA-Z])', ' ', text)
    # Preserve newlines between paragraphs
    text = re.sub(r'\n\s*\n', '\n\n', text)
    # Remove trailing whitespace characters from lines
    text = re.sub(r'[ \t]+$', '', text, flags=re.MULTILINE)
    return text.strip()
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