-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into embedded_image
- Loading branch information
Showing
10 changed files
with
151 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
[![PyPI](https://img.shields.io/pypi/v/markitdown.svg)](https://pypi.org/project/markitdown/) | ||
![PyPI - Downloads](https://img.shields.io/pypi/dd/markitdown) | ||
[![Built by AutoGen Team](https://img.shields.io/badge/Built%20by-AutoGen%20Team-blue)](https://github.com/microsoft/autogen) | ||
|
||
|
||
MarkItDown is a utility for converting various files to Markdown (e.g., for indexing, text analysis, etc). | ||
|
@@ -29,6 +30,12 @@ To install MarkItDown, use pip: `pip install markitdown`. Alternatively, you can | |
markitdown path-to-file.pdf > document.md | ||
``` | ||
|
||
Or use `-o` to specify the output file: | ||
|
||
```bash | ||
markitdown path-to-file.pdf -o document.md | ||
``` | ||
|
||
You can also pipe content: | ||
|
||
```bash | ||
|
@@ -65,7 +72,43 @@ print(result.text_content) | |
docker build -t markitdown:latest . | ||
docker run --rm -i markitdown:latest < ~/your-file.pdf > output.md | ||
``` | ||
<details> | ||
|
||
<summary>Batch Processing Multiple Files</summary> | ||
|
||
This example shows how to convert multiple files to markdown format in a single run. The script processes all supported files in a directory and creates corresponding markdown files. | ||
|
||
|
||
```python convert.py | ||
from markitdown import MarkItDown | ||
from openai import OpenAI | ||
import os | ||
client = OpenAI(api_key="your-api-key-here") | ||
md = MarkItDown(llm_client=client, llm_model="gpt-4o-2024-11-20") | ||
supported_extensions = ('.pptx', '.docx', '.pdf', '.jpg', '.jpeg', '.png') | ||
files_to_convert = [f for f in os.listdir('.') if f.lower().endswith(supported_extensions)] | ||
for file in files_to_convert: | ||
print(f"\nConverting {file}...") | ||
try: | ||
md_file = os.path.splitext(file)[0] + '.md' | ||
result = md.convert(file) | ||
with open(md_file, 'w') as f: | ||
f.write(result.text_content) | ||
|
||
print(f"Successfully converted {file} to {md_file}") | ||
except Exception as e: | ||
print(f"Error converting {file}: {str(e)}") | ||
|
||
print("\nAll conversions completed!") | ||
``` | ||
2. Place the script in the same directory as your files | ||
3. Install required packages: like openai | ||
4. Run script ```bash python convert.py ``` | ||
|
||
Note that original files will remain unchanged and new markdown files are created with the same base name. | ||
|
||
</details> | ||
|
||
## Contributing | ||
|
||
This project welcomes contributions and suggestions. Most contributions require you to agree to a | ||
|
@@ -80,6 +123,20 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope | |
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or | ||
contact [[email protected]](mailto:[email protected]) with any additional questions or comments. | ||
|
||
### How to Contribute | ||
|
||
You can help by looking at issues or helping review PRs. Any issue or PR is welcome, but we have also marked some as 'open for contribution' and 'open for reviewing' to help facilitate community contributions. These are ofcourse just suggestions and you are welcome to contribute in any way you like. | ||
|
||
|
||
<div align="center"> | ||
|
||
| | All | Especially Needs Help from Community | | ||
|-----------------------|------------------------------------------|------------------------------------------------------------------------------------------| | ||
| **Issues** | [All Issues](https://github.com/microsoft/markitdown/issues) | [Issues open for contribution](https://github.com/microsoft/markitdown/issues?q=is%3Aissue+is%3Aopen+label%3A%22open+for+contribution%22) | | ||
| **PRs** | [All PRs](https://github.com/microsoft/markitdown/pulls) | [PRs open for reviewing](https://github.com/microsoft/markitdown/pulls?q=is%3Apr+is%3Aopen+label%3A%22open+for+reviewing%22) | | ||
|
||
</div> | ||
|
||
### Running Tests and Checks | ||
|
||
- Install `hatch` in your environment and run tests: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,80 @@ | ||
# SPDX-FileCopyrightText: 2024-present Adam Fourney <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
import sys | ||
import argparse | ||
import sys | ||
from textwrap import dedent | ||
from ._markitdown import MarkItDown | ||
from .__about__ import __version__ | ||
from ._markitdown import MarkItDown, DocumentConverterResult | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description="Convert various file formats to markdown.", | ||
prog="markitdown", | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
usage=dedent( | ||
""" | ||
SYNTAX: | ||
SYNTAX: | ||
markitdown <OPTIONAL: FILENAME> | ||
If FILENAME is empty, markitdown reads from stdin. | ||
EXAMPLE: | ||
markitdown example.pdf | ||
OR | ||
cat example.pdf | markitdown | ||
OR | ||
OR | ||
markitdown < example.pdf | ||
OR to save to a file use | ||
markitdown example.pdf -o example.md | ||
OR | ||
markitdown example.pdf > example.md | ||
""" | ||
).strip(), | ||
) | ||
|
||
parser.add_argument( | ||
"-v", | ||
"--version", | ||
action="version", | ||
version=f"%(prog)s {__version__}", | ||
help="show the version number and exit", | ||
) | ||
|
||
parser.add_argument("filename", nargs="?") | ||
parser.add_argument( | ||
"-o", | ||
"--output", | ||
help="Output file name. If not provided, output is written to stdout.", | ||
) | ||
args = parser.parse_args() | ||
|
||
if args.filename is None: | ||
markitdown = MarkItDown() | ||
result = markitdown.convert_stream(sys.stdin.buffer) | ||
print(result.text_content) | ||
_handle_output(args, result) | ||
else: | ||
markitdown = MarkItDown() | ||
result = markitdown.convert(args.filename) | ||
_handle_output(args, result) | ||
|
||
|
||
def _handle_output(args, result: DocumentConverterResult): | ||
"""Handle output to stdout or file""" | ||
if args.output: | ||
with open(args.output, "w", encoding="utf-8") as f: | ||
f.write(result.text_content) | ||
else: | ||
print(result.text_content) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters