Skip to content

Commit

Permalink
slight tidy
Browse files Browse the repository at this point in the history
- follow-up to microsoft#46
  • Loading branch information
casperdcl committed Dec 17, 2024
1 parent ad5d4fb commit b58cc00
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions src/markitdown/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,19 @@ def main():
parser = argparse.ArgumentParser(
description="Convert various file formats to markdown.",
formatter_class=argparse.RawDescriptionHelpFormatter,
usage="""
SYNTAX:
markitdown <OPTIONAL: FILENAME>
If FILENAME is empty, markitdown reads from stdin.
EXAMPLE:
markitdown example.pdf
OR
cat example.pdf | markitdown
OR
markitdown < example.pdf
""".strip(),
epilog="""examples:
markitdown example.pdf
cat example.pdf | markitdown
markitdown < example.pdf""",
)

parser.add_argument("filename", nargs="?")
parser.add_argument(
"filename", nargs="?", help="if unspecified, defaults to stdin"
)
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)
markitdown = MarkItDown()
result = markitdown.convert(args.filename or sys.stdin.buffer)
print(result.text_content)


if __name__ == "__main__":
Expand Down

0 comments on commit b58cc00

Please sign in to comment.