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

fix: upgrade pdftext #30

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ version_provider = "poetry"
# Python:
python = ">=3.10,<4.0"
# Markdown conversion:
pdftext = ">=0.3.10,!=0.3.11"
pdftext = ">=0.3.13"
pypandoc-binary = { version = ">=1.13", optional = true }
scikit-learn = ">=1.4.2"
# Markdown formatting:
Expand Down
6 changes: 1 addition & 5 deletions src/raglite/_markdown.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Convert any document to Markdown."""

import re
import warnings
from copy import deepcopy
from pathlib import Path
from typing import Any
Expand All @@ -10,7 +9,6 @@
import numpy as np
from pdftext.extraction import dictionary_output
from sklearn.cluster import KMeans
from sklearn.exceptions import InconsistentVersionWarning


def parsed_pdf_to_markdown(pages: list[dict[str, Any]]) -> list[str]: # noqa: C901, PLR0915
Expand Down Expand Up @@ -202,9 +200,7 @@ def document_to_markdown(doc_path: Path) -> str:
# Convert the file's content to GitHub Flavored Markdown.
if doc_path.suffix == ".pdf":
# Parse the PDF with pdftext and convert it to Markdown.
with warnings.catch_warnings(): # Ignore https://github.com/VikParuchuri/pdftext/issues/5.
warnings.simplefilter("ignore", InconsistentVersionWarning)
pages = dictionary_output(doc_path, sort=True, keep_chars=False)
pages = dictionary_output(doc_path, sort=True, keep_chars=False)
doc = "\n\n".join(parsed_pdf_to_markdown(pages))
else:
# Use pandoc for everything else.
Expand Down
Loading