Skip to content

Add page_indexes parameter to transform functions#325

Open
HuSharp wants to merge 2 commits intooomol-lab:mainfrom
HuSharp:support_page_index
Open

Add page_indexes parameter to transform functions#325
HuSharp wants to merge 2 commits intooomol-lab:mainfrom
HuSharp:support_page_index

Conversation

@HuSharp
Copy link
Copy Markdown

@HuSharp HuSharp commented Jan 7, 2026

Usage Example

  transform_markdown(
      pdf_path="document.pdf",
      markdown_path="output.md",
      page_indexes=range(1, 11),  # Pages 1-10 only
  )

Signed-off-by: Jinhao Hu <jihu00003@stud.uni-saarland.de>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 7, 2026

Summary by CodeRabbit

  • New Features
    • Added optional page selection to PDF conversion tools so users can specify which pages to process when exporting to Markdown or EPUB. The selection is honored throughout the conversion flow, enabling partial-document conversions without changing existing defaults.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

This change adds an optional page_indexes: range | None = None parameter to the public functions transform_markdown and transform_epub in pdf_craft/functions.py, and to the corresponding methods transform_markdown, transform_epub, and _extract_from_pdf in pdf_craft/transform.py. The parameter is threaded through these call sites and, when provided, included in a recognize_kwargs dictionary passed to the OCR recognition call so callers can restrict OCR to specified page ranges.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • oomol-lab/pdf-craft PR 314: Modifies the same transformation call chain by adding and threading a new optional parameter through transform_markdown, transform_epub, and related internals.
🚥 Pre-merge checks | ✅ 1 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title does not follow the required format of <type>(<scope>): <subject>. It is missing the type prefix and follows a generic pattern instead. Reformat the title to follow the required pattern, for example: feat(functions): add page_indexes parameter to transform functions
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description is related to the changeset, providing a concrete usage example of the new page_indexes parameter being added to the transform functions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a20de28 and f9dd20c.

📒 Files selected for processing (1)
  • pdf_craft/transform.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • pdf_craft/transform.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pdf_craft/transform.py (1)

129-152: Critical: page_indexes parameter not forwarded to _extract_from_pdf.

The page_indexes parameter is declared in the transform_epub signature but is never passed to the _extract_from_pdf call at lines 136-152. This means EPUB transformations will ignore the page_indexes parameter entirely, causing silent malfunction for users who expect selective page processing.

🐛 Proposed fix: Forward page_indexes to _extract_from_pdf
                 asserts_path, chapters_path, toc_path, cover_path, metering = self._extract_from_pdf(
                     pdf_path=pdf_path,
                     analysing_path=analysing_path,
                     ocr_size=ocr_size,
                     dpi=dpi,
                     max_page_image_file_size=max_page_image_file_size,
                     includes_cover=includes_cover,
                     includes_footnotes=includes_footnotes,
                     ignore_pdf_errors=ignore_pdf_errors,
                     ignore_ocr_errors=ignore_ocr_errors,
                     generate_plot=generate_plot,
                     toc_assumed=toc_assumed,
                     aborted=aborted,
                     max_tokens=max_ocr_tokens,
                     max_output_tokens=max_ocr_output_tokens,
                     on_ocr_event=on_ocr_event,
+                    page_indexes=page_indexes,
                 )
🧹 Nitpick comments (1)
pdf_craft/transform.py (1)

215-234: LGTM: Clean conditional parameter forwarding pattern.

The recognize_kwargs dictionary construction with conditional inclusion of page_indexes is well-implemented and correctly forwards parameters to the OCR layer.

Consider whether restricting the parameter type to range | None is intentional. The underlying OCR.recognize method accepts Container[int], which would allow users to pass list[int], set[int], or other containers for more flexible page selection (e.g., non-contiguous pages like [1, 5, 10, 15]). If the API intentionally restricts to ranges for simplicity, this is fine; otherwise, broadening the type might improve flexibility.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9cfbcea and a20de28.

📒 Files selected for processing (2)
  • pdf_craft/functions.py
  • pdf_craft/transform.py
🧰 Additional context used
🧬 Code graph analysis (1)
pdf_craft/transform.py (1)
pdf_craft/pdf/ocr.py (1)
  • recognize (66-211)
🪛 Ruff (0.14.10)
pdf_craft/transform.py

129-129: Unused method argument: page_indexes

(ARG002)

🔇 Additional comments (4)
pdf_craft/transform.py (2)

58-58: LGTM: Parameter addition to transform_markdown.

The page_indexes parameter is properly added and correctly forwarded to _extract_from_pdf at line 85.


196-196: LGTM: Parameter addition to _extract_from_pdf.

The parameter is properly integrated and correctly used in the recognize_kwargs construction.

pdf_craft/functions.py (2)

46-71: LGTM: Parameter addition and forwarding in transform_markdown.

The page_indexes parameter is correctly added to the public API and properly forwarded to the Transform layer.


100-129: LGTM: Parameter addition and forwarding in transform_epub.

The parameter forwarding is correct at this layer. However, note that there's a critical bug downstream in Transform.transform_epub (flagged in the transform.py review) where the parameter is not forwarded to _extract_from_pdf.

Signed-off-by: Jinhao Hu <jihu00003@stud.uni-saarland.de>
@HuSharp
Copy link
Copy Markdown
Author

HuSharp commented Jan 7, 2026

@coderabbitai help

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 7, 2026

Tip

For best results, initiate chat on the files or code changes.

@HuSharp, hello! How can I assist you with this PR? I can help with:

  • Reviewing the changes - I can perform a detailed code review of your page_indexes parameter implementation
  • Answering questions - If you have any questions about the implementation or suggestions
  • Generating tests - I can help create unit tests for the new functionality
  • Documentation - I can help with documentation or usage examples
  • Other requests - Any other specific task you'd like me to help with

Just let me know what you need!

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 7, 2026

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue comments.

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
    • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
    • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai generate configuration to create a PR that adds the current resolved configuration as .coderabbit.yaml (or show it if already present).
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @cr summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @cr anywhere in the PR title to generate the title automatically.

CodeRabbit configuration file (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

@HuSharp
Copy link
Copy Markdown
Author

HuSharp commented Jan 7, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 7, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Successfully merging this pull request may close these issues.

1 participant