Skip to content

Commit

Permalink
Merge pull request #77 from microsoft/kevinclb/main
Browse files Browse the repository at this point in the history
Kevinclb/main
  • Loading branch information
gagb authored Dec 17, 2024
2 parents c8980d9 + ad29122 commit ad5d4fb
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/markitdown/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@
#
# SPDX-License-Identifier: MIT
import sys
import argparse
from ._markitdown import MarkItDown


def main():
if len(sys.argv) == 1:
markitdown = MarkItDown()
result = markitdown.convert_stream(sys.stdin.buffer)
print(result.text_content)
elif len(sys.argv) == 2:
markitdown = MarkItDown()
result = markitdown.convert(sys.argv[1])
print(result.text_content)
else:
sys.stderr.write(
"""
parser = argparse.ArgumentParser(
description="Convert various file formats to markdown.",
formatter_class=argparse.RawDescriptionHelpFormatter,
usage="""
SYNTAX:
markitdown <OPTIONAL: FILENAME>
Expand All @@ -33,9 +27,20 @@ def main():
OR
markitdown < example.pdf
""".strip()
+ "\n"
)
""".strip(),
)

parser.add_argument("filename", nargs="?")
args = parser.parse_args()

if args.filename is None:
markitdown = MarkItDown()
result = markitdown.convert_stream(sys.stdin.buffer)
print(result.text_content)
else:
markitdown = MarkItDown()
result = markitdown.convert(args.filename)
print(result.text_content)


if __name__ == "__main__":
Expand Down

0 comments on commit ad5d4fb

Please sign in to comment.