markitdown 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- markitdown/__about__.py +4 -0
- markitdown/__init__.py +11 -0
- markitdown/__main__.py +111 -0
- markitdown/_markitdown.py +1814 -0
- markitdown/py.typed +0 -0
- markitdown-0.0.1.dist-info/METADATA +219 -0
- markitdown-0.0.1.dist-info/RECORD +10 -0
- markitdown-0.0.1.dist-info/WHEEL +4 -0
- markitdown-0.0.1.dist-info/entry_points.txt +2 -0
- markitdown-0.0.1.dist-info/licenses/LICENSE +21 -0
markitdown/__about__.py
ADDED
markitdown/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024-present Adam Fourney <adamfo@microsoft.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
from ._markitdown import MarkItDown, FileConversionException, UnsupportedFormatException
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"MarkItDown",
|
|
9
|
+
"FileConversionException",
|
|
10
|
+
"UnsupportedFormatException",
|
|
11
|
+
]
|
markitdown/__main__.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024-present Adam Fourney <adamfo@microsoft.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
import argparse
|
|
5
|
+
import sys
|
|
6
|
+
import shutil
|
|
7
|
+
from textwrap import dedent
|
|
8
|
+
from .__about__ import __version__
|
|
9
|
+
from ._markitdown import MarkItDown, DocumentConverterResult
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
parser = argparse.ArgumentParser(
|
|
14
|
+
description="Convert various file formats to markdown.",
|
|
15
|
+
prog="markitdown",
|
|
16
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
17
|
+
usage=dedent(
|
|
18
|
+
"""
|
|
19
|
+
SYNTAX:
|
|
20
|
+
|
|
21
|
+
markitdown <OPTIONAL: FILENAME>
|
|
22
|
+
If FILENAME is empty, markitdown reads from stdin.
|
|
23
|
+
|
|
24
|
+
EXAMPLE:
|
|
25
|
+
|
|
26
|
+
markitdown example.pdf
|
|
27
|
+
|
|
28
|
+
OR
|
|
29
|
+
|
|
30
|
+
cat example.pdf | markitdown
|
|
31
|
+
|
|
32
|
+
OR
|
|
33
|
+
|
|
34
|
+
markitdown < example.pdf
|
|
35
|
+
|
|
36
|
+
OR to save to a file use
|
|
37
|
+
|
|
38
|
+
markitdown example.pdf -o example.md
|
|
39
|
+
|
|
40
|
+
OR
|
|
41
|
+
|
|
42
|
+
markitdown example.pdf > example.md
|
|
43
|
+
"""
|
|
44
|
+
).strip(),
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
parser.add_argument(
|
|
48
|
+
"-v",
|
|
49
|
+
"--version",
|
|
50
|
+
action="version",
|
|
51
|
+
version=f"%(prog)s {__version__}",
|
|
52
|
+
help="show the version number and exit",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
parser.add_argument(
|
|
56
|
+
"-o",
|
|
57
|
+
"--output",
|
|
58
|
+
help="Output file name. If not provided, output is written to stdout.",
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
parser.add_argument(
|
|
62
|
+
"-d",
|
|
63
|
+
"--use-docintel",
|
|
64
|
+
action="store_true",
|
|
65
|
+
help="Use Document Intelligence to extract text instead of offline conversion. Requires a valid Document Intelligence Endpoint.",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
parser.add_argument(
|
|
69
|
+
"-e",
|
|
70
|
+
"--endpoint",
|
|
71
|
+
type=str,
|
|
72
|
+
help="Document Intelligence Endpoint. Required if using Document Intelligence.",
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
parser.add_argument("filename", nargs="?")
|
|
76
|
+
args = parser.parse_args()
|
|
77
|
+
|
|
78
|
+
which_exiftool = shutil.which("exiftool")
|
|
79
|
+
|
|
80
|
+
if args.use_docintel:
|
|
81
|
+
if args.endpoint is None:
|
|
82
|
+
raise ValueError(
|
|
83
|
+
"Document Intelligence Endpoint is required when using Document Intelligence."
|
|
84
|
+
)
|
|
85
|
+
elif args.filename is None:
|
|
86
|
+
raise ValueError("Filename is required when using Document Intelligence.")
|
|
87
|
+
markitdown = MarkItDown(
|
|
88
|
+
exiftool_path=which_exiftool, docintel_endpoint=args.endpoint
|
|
89
|
+
)
|
|
90
|
+
else:
|
|
91
|
+
markitdown = MarkItDown(exiftool_path=which_exiftool)
|
|
92
|
+
|
|
93
|
+
if args.filename is None:
|
|
94
|
+
result = markitdown.convert_stream(sys.stdin.buffer)
|
|
95
|
+
else:
|
|
96
|
+
result = markitdown.convert(args.filename)
|
|
97
|
+
|
|
98
|
+
_handle_output(args, result)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _handle_output(args, result: DocumentConverterResult):
|
|
102
|
+
"""Handle output to stdout or file"""
|
|
103
|
+
if args.output:
|
|
104
|
+
with open(args.output, "w", encoding="utf-8") as f:
|
|
105
|
+
f.write(result.text_content)
|
|
106
|
+
else:
|
|
107
|
+
print(result.text_content)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if __name__ == "__main__":
|
|
111
|
+
main()
|