Skip to content

Added Python MarkItDown docs #1977

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Added Python MarkItDown docs #1977

wants to merge 5 commits into from

Conversation

D-K-P
Copy link
Member

@D-K-P D-K-P commented Apr 24, 2025

Summary by CodeRabbit

  • New Features

    • Added a new guide on converting documents to markdown using Python and the MarkItDown library.
    • Updated the documentation navigation and introduction to include the new "Python document to markdown" guide.
  • Documentation

    • Provided step-by-step instructions, prerequisites, and example code for integrating document conversion into your workflow.
    • Included details on supported file formats, features, and links to additional resources.
    • Updated sidebar titles for several Python guides to improve clarity and consistency.

Copy link

changeset-bot bot commented Apr 24, 2025

⚠️ No Changeset found

Latest commit: 322e1b6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Apr 24, 2025

Walkthrough

A new guide focused on converting documents to markdown using Python and the Microsoft MarkItDown library has been added to the documentation. The navigation structure is updated to include this guide under the Python guides section. The introduction page for guides now references the new document conversion guide, and a comprehensive instructional document is introduced, detailing setup, implementation, and usage of the conversion process within a Trigger.dev project. Additionally, some sidebar titles in existing Python guides were updated for clarity.

Changes

File(s) Change Summary
docs/docs.json Added a new navigation entry for "guides/python/python-doc-to-markdown" under the Python guides section.
docs/guides/introduction.mdx Added an entry for the new "Python document to markdown" guide in the introduction list of guides.
docs/guides/python/python-doc-to-markdown.mdx Introduced a new detailed guide for converting documents to markdown using Python and MarkItDown in Trigger.dev.
docs/guides/python/python-crawl4ai.mdx Updated sidebar title metadata from "Python headless web crawler" to "Headless web crawler".
docs/guides/python/python-image-processing.mdx Updated sidebar title metadata from "Python image processing" to "Process images".
docs/guides/python/python-pdf-form-extractor.mdx Updated sidebar title metadata from "Python PDF form extractor" to "Extract form data from PDFs".

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TriggerDev
    participant PythonScript
    participant MarkItDown

    User->>TriggerDev: Initiate document conversion task (provide URL)
    TriggerDev->>TriggerDev: Download document to temp file
    TriggerDev->>PythonScript: Run Python script with temp file path
    PythonScript->>MarkItDown: Convert document to markdown
    MarkItDown-->>PythonScript: Return markdown or error
    PythonScript->>TriggerDev: Return conversion result (success/error, markdown)
    TriggerDev->>TriggerDev: Clean up temp files
    TriggerDev->>User: Return conversion result (markdown, error, success)
Loading

Suggested reviewers

  • nicktrn

Poem

In docs a new guide takes its stand,
Python and MarkItDown, paw-in-hand.
From docs to markdown, the process is clear,
With Trigger.dev magic, the steps appear.
Hop along, convert with glee—
A rabbit’s guide for all to see!
🐇✨📄➡️📝


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
🪧 Tips

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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai 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.
  • 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

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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: 1

🧹 Nitpick comments (3)
docs/guides/python/python-doc-to-markdown.mdx (3)

1-5: Validate frontmatter metadata
Frontmatter fields (title, sidebarTitle, description) follow the established pattern. Consider verifying that “Markdown” capitalization here aligns with other guide titles or branding guidelines.


41-62: Clarify OS-specific instructions in build snippet
The devPythonBinaryPath: \venv/bin/python`setting works on Unix-like systems but not on Windows. You may want to add a note or show a Windows equivalent (e.g.,venv\Scripts\python.exe`) for Windows users.


123-129: Improve temporary file cleanup
The fs.unlink call is non-blocking and swallows errors. To ensure no leftover files and better error visibility, consider awaiting the unlink or adding an error callback, for example:

await fs.promises.unlink(tempFilePath);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32ff569 and 7a3e4ce.

📒 Files selected for processing (3)
  • docs/docs.json (1 hunks)
  • docs/guides/introduction.mdx (1 hunks)
  • docs/guides/python/python-doc-to-markdown.mdx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/guides/python/python-doc-to-markdown.mdx

[uncategorized] ~15-~15: A punctuation mark might be missing here.
Context: ... A project with Trigger.dev initialized - Python install...

(AI_EN_LECTOR_MISSING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (5)
docs/docs.json (1)

314-316: Add new Python document-to-markdown guide to navigation
The entry "guides/python/python-doc-to-markdown" was correctly inserted under the “Python guides” group. Please verify that the .mdx file at docs/guides/python/python-doc-to-markdown.mdx exists and matches this path.

docs/guides/introduction.mdx (1)

31-33: Include new guide in the introduction table
The new table row linking to /guides/python/python-doc-to-markdown accurately reflects the added guide. Table alignment and link text look consistent with surrounding entries.

docs/guides/python/python-doc-to-markdown.mdx (3)

7-7: Verify snippet import path
Make sure the /snippets/python-learn-more.mdx component is present and renders correctly. Otherwise, the <PythonLearnMore /> include at the end of the file will fail.


231-234: Handle script exit codes consistently
When markdown-converter.py exits with a non-zero status on missing args, it prints JSON then calls sys.exit(1). Verify that python.runScript doesn’t throw on non-zero codes (which would bypass your stdout/stderr logic), or adjust the Python script to return a 0 exit code with an error object.


209-211: Confirm MarkItDown return API
The code uses result = md.convert(file_path) and returns result.text_content. Please verify that the MarkItDown API exposes a text_content property. If the returned object uses a different field (e.g., markdown), update accordingly.

Copy link
Contributor

@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: 1

🧹 Nitpick comments (5)
docs/guides/python/python-doc-to-markdown.mdx (5)

9-13: Consistent casing for "Markdown"
Consider capitalizing "Markdown" (e.g., "Convert documents to Markdown") to match the conventional naming of the format across the title and content.


13-17: Add missing punctuation for consistency
The first bullet under Prerequisites lacks a trailing period, while the second bullet includes one. For uniformity, either end all bullets with a period or omit them consistently.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~15-~15: A punctuation mark might be missing here.
Context: ... A project with Trigger.dev initialized - Python install...

(AI_EN_LECTOR_MISSING_PUNCTUATION)


87-92: Improve temp file naming randomness
Using Date.now() and Math.random() reduces collisions but consider using a UUID (e.g., crypto.randomUUID()) for stronger uniqueness guarantees.


113-114: Handle cleanup errors or use promises
The fs.unlink callback is empty, silently ignoring errors. Consider using fs.promises.unlink or handling the callback’s error parameter for improved reliability.


116-125: Robust parsing of Python output
JSON.parse(pythonResult.stdout) assumes valid JSON. Wrap parsing in a try/catch, and handle pythonResult.stderr to surface conversion errors instead of falling back to the generic "No output" case.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7a3e4ce and 93cac41.

📒 Files selected for processing (1)
  • docs/guides/python/python-doc-to-markdown.mdx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/guides/python/python-doc-to-markdown.mdx

[uncategorized] ~15-~15: A punctuation mark might be missing here.
Context: ... A project with Trigger.dev initialized - Python install...

(AI_EN_LECTOR_MISSING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (16)
docs/guides/python/python-doc-to-markdown.mdx (16)

1-5: Frontmatter metadata is well-defined
The title, sidebarTitle, and description fields are clear and descriptive.


7-7: Confirm snippet import path
Ensure that the /snippets/python-learn-more.mdx file exists and correctly exports the PythonLearnMore component for use in this guide.


18-23: Features section is clear and concise
The bullet points accurately summarize the guide's core features and are easy to scan.


26-33: Verify the example repository link
Please confirm that the GitHub URL (https://github.com/triggerdotdev/examples/tree/main/python-doc-to-markdown-converter) points to the intended example project and is kept up to date.


41-62: Validate code block metadata
The fence syntax (```ts trigger.config.ts) may not be recognized by all MDX parsers. Confirm that the code block metadata renders the filename correctly in the documentation site.


64-67: Info component usage is appropriate
The <Info> callout directs users to additional docs and is well-placed after the build snippet.


73-81: Imports are relevant and utilized
All imported modules (fs, path, os, https, http) are used in the task implementation.


108-112: Confirm script path resolution
Ensure that python.runScript("./src/python/markdown-converter.py", …) resolves correctly at runtime within the build environment.


127-132: Fallback return is clear
The default return structure for missing stdout is straightforward and informative for debugging.


141-143: Python dependency specification is correct
Listing markitdown[all] in requirements.txt aligns with the guide’s instructions for installing all optional extras.


155-168: Conversion function is well-structured
The convert_to_markdown function correctly checks for file existence, initializes the library, and raises exceptions on failure.


171-183: Trigger task processing logic is solid
process_trigger_task cleanly differentiates between success and error states and returns a consistent JSON structure.


185-203: Main execution block handles arguments
The __main__ section validates input, prints structured JSON on both success and failure, and sets the exit code appropriately.


208-215: Testing instructions are comprehensive
The step-by-step guide covers environment setup, dependency installation, configuration, local testing, and deployment.


218-229: Verify nested list rendering
The nested list under “Convert various file formats to Markdown” uses two-space indentation. Confirm that this renders correctly on the site as a sublist.


230-230: Final snippet call is correct
The <PythonLearnMore /> component matches the import and is placed appropriately at the end of the guide.

Comment on lines 95 to 106
await new Promise<void>((resolve, reject) => {
const protocol = url.startsWith("https") ? https : http;
const file = fs.createWriteStream(tempFilePath);

protocol.get(url, (response) => {
response.pipe(file);
file.on("finish", () => {
file.close();
resolve();
});
});
});
Copy link
Member

Choose a reason for hiding this comment

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

@D-K-P I don't think it's needed to save the file like this. It can be useful to do streams when dealing with large files, but for a doc I think it'd be better to download it using fetch and then save the response to the file. http is a super old school Node.js thing that I wouldn't recommend anymore

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair point have just updated

Copy link
Member

@matt-aitken matt-aitken left a comment

Choose a reason for hiding this comment

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

Let's change the way the file is downloaded to just use fetch. Other than that this is really cool

Copy link
Contributor

@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: 1

🧹 Nitpick comments (1)
docs/guides/python/python-doc-to-markdown.mdx (1)

107-109: Optional: Improve temp-file cleanup
Using fs.unlink with an empty callback may hide cleanup errors. Consider using the promise-based API for better consistency:

-    fs.unlink(tempFilePath, () => {});
+    try {
+      await fs.promises.unlink(tempFilePath);
+    } catch {
+      // ignore any errors during cleanup
+    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93cac41 and 5eda055.

📒 Files selected for processing (4)
  • docs/guides/python/python-crawl4ai.mdx (1 hunks)
  • docs/guides/python/python-doc-to-markdown.mdx (1 hunks)
  • docs/guides/python/python-image-processing.mdx (1 hunks)
  • docs/guides/python/python-pdf-form-extractor.mdx (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • docs/guides/python/python-image-processing.mdx
  • docs/guides/python/python-pdf-form-extractor.mdx
  • docs/guides/python/python-crawl4ai.mdx
🧰 Additional context used
🪛 LanguageTool
docs/guides/python/python-doc-to-markdown.mdx

[uncategorized] ~20-~20: A punctuation mark might be missing here.
Context: ... A project with Trigger.dev initialized - Python install...

(AI_EN_LECTOR_MISSING_PUNCTUATION)

🪛 GitHub Actions: 📚 Docs Checks
docs/guides/python/python-doc-to-markdown.mdx

[error] 1-1: Broken link found: /docs/upgrade-to-v4. Run link checker to fix broken links.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (14)
docs/guides/python/python-doc-to-markdown.mdx (14)

1-5: Frontmatter metadata looks good
The title, sidebarTitle, and description are clear and follow existing conventions.

🧰 Tools
🪛 GitHub Actions: 📚 Docs Checks

[error] 1-1: Broken link found: /docs/upgrade-to-v4. Run link checker to fix broken links.


7-7: Verify snippet import path
Please confirm that the file /snippets/python-learn-more.mdx exists at this location and resolves correctly in the built site.


14-17: Overview section is clear
The overview succinctly explains the purpose and value of using MarkItDown with Trigger.dev.


18-23: Verify internal quick-start link
Ensure that the /quick-start link correctly points to your project initialization guide. If your quick-start page lives under /docs/quick-start, please adjust accordingly.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~20-~20: A punctuation mark might be missing here.
Context: ... A project with Trigger.dev initialized - Python install...

(AI_EN_LECTOR_MISSING_PUNCTUATION)


24-28: Features list is well-structured
The bullet list clearly outlines what this guide provides.


29-38: GitHub repo Card is correct
The Card component usage and link to the examples repository look accurate.


46-67: Build configuration snippet is accurate
The code block for trigger.config.ts includes the right imports and options for the Python extension.


69-72: Info callout is helpful
The information about the Python build extension link is clear and correctly formatted.


78-129: Task implementation snippet is clear
The TypeScript example for convertToMarkdown follows our SDK patterns and provides a full end-to-end demonstration.


135-137: Requirements snippet is correct
The requirements.txt code block and dependency declaration are straightforward.


143-198: Python script example is solid
The script covers error handling, JSON I/O, and demonstrates MarkItDown usage clearly.


200-209: Testing instructions are complete
The step-by-step guide to creating a venv and running the task locally is clear and actionable.


212-223: Conversion capabilities list is comprehensive
The bulleted capabilities cover all supported formats and features.


224-224: Embedded learn-more snippet
The <PythonLearnMore /> component at the end reinforces further reading.

Copy link
Contributor

@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: 2

♻️ Duplicate comments (1)
docs/guides/python/python-doc-to-markdown.mdx (1)

97-101: 🛠️ Refactor suggestion

Add HTTP status check when downloading the document.
The code writes whatever comes back from fetch directly to disk, even on 404/500 responses. To catch HTTP errors early, you can do:

- const response = await fetch(url);
+ const response = await fetch(url);
+ if (!response.ok) {
+   throw new Error(`Failed to download document: ${response.status} ${response.statusText}`);
+ }

This ensures you don’t pass an HTML error page into your converter.

🧹 Nitpick comments (2)
docs/guides/python/python-doc-to-markdown.mdx (2)

20-21: Consistency: add punctuation to bullet list.
For uniformity, consider adding a trailing period to the first prerequisite (- A project with [Trigger.dev initialized](/quick-start).) so it matches the style of the subsequent bullet.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~20-~20: A punctuation mark might be missing here.
Context: ... A project with Trigger.dev initialized - Python install...

(AI_EN_LECTOR_MISSING_PUNCTUATION)


103-109: Improve error handling for the Python script and file cleanup.
Currently, failures from python.runScript aren’t surfaced, and fs.unlink swallows errors. Consider wrapping the call in try/catch/finally, checking pythonResult.exitCode or stderr, and using fs.promises.unlink:

- const pythonResult = await python.runScript("./src/python/markdown-converter.py", [
-   JSON.stringify({ file_path: tempFilePath }),
- ]);
- fs.unlink(tempFilePath, () => {});
+ let pythonResult;
+ try {
+   pythonResult = await python.runScript(
+     "./src/python/markdown-converter.py",
+     [JSON.stringify({ file_path: tempFilePath })]
+   );
+   if (pythonResult.exitCode !== 0) {
+     throw new Error(
+       `Python script failed (${pythonResult.exitCode}): ${pythonResult.stderr}`
+     );
+   }
+ } finally {
+   try {
+     await fs.promises.unlink(tempFilePath);
+   } catch (cleanupErr) {
+     console.warn("Cleanup error:", cleanupErr);
+   }
+ }

This pattern ensures robust error propagation and reliable cleanup.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5eda055 and 322e1b6.

📒 Files selected for processing (2)
  • docs/docs.json (1 hunks)
  • docs/guides/python/python-doc-to-markdown.mdx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/docs.json
🧰 Additional context used
🪛 LanguageTool
docs/guides/python/python-doc-to-markdown.mdx

[uncategorized] ~20-~20: A punctuation mark might be missing here.
Context: ... A project with Trigger.dev initialized - Python install...

(AI_EN_LECTOR_MISSING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
docs/guides/python/python-doc-to-markdown.mdx (2)

7-8: Verify snippet import path for PythonLearnMore.
The MDX import uses an absolute path ("/snippets/python-learn-more.mdx"). Please confirm that this file exists at that location or change to a relative import (e.g., ../snippets/python-learn-more.mdx) to avoid broken imports at build time.


143-198: Python script implementation is clear and robust.
The markdown-converter.py handles missing files, wraps exceptions in JSON, and matches the TypeScript consumer’s expectations. Well structured, commented, and easy to follow.

Comment on lines +9 to +12
<Note>
This project uses Trigger.dev v4 (which is currently in beta as of 28 April 2025). If you want to
run this project you will need to [upgrade to v4](/upgrade-to-v4).
</Note>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Broken “upgrade to v4” link in Note.
The callout points at /upgrade-to-v4, but our v4 upgrade guide lives under /docs/guides/upgrade-to-v4 (or similar). Update the link to the correct path to prevent a 404 in the docs.

Comment on lines +46 to +67
```ts trigger.config.ts
import { pythonExtension } from "@trigger.dev/python/extension";
import { defineConfig } from "@trigger.dev/sdk/v3";

export default defineConfig({
runtime: "node",
project: "<your-project-ref>",
// Your other config settings...
build: {
extensions: [
pythonExtension({
// The path to your requirements.txt file
requirementsFile: "./requirements.txt",
// The path to your Python binary
devPythonBinaryPath: `venv/bin/python`,
// The paths to your Python scripts to run
scripts: ["src/python/**/*.py"],
}),
],
},
});
```
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Inconsistent SDK version vs. Note v4 reference.
The guide introduction mentions Trigger.dev v4 (beta), but this snippet imports from @trigger.dev/sdk/v3. Please either:

  • Update the snippet to use the v4 SDK package (e.g., @trigger.dev/sdk/v4),
  • Or adjust the Note to indicate that this example targets v3.
    Aligning versions avoids confusion.

@triggerdotdev triggerdotdev deleted a comment from coderabbitai bot Apr 29, 2025
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.

2 participants