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 20, 2024
1 parent 18e3f1d commit 6ea36f9
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions src/markitdown/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,22 @@ def main():
parser = argparse.ArgumentParser(
description="Convert various file formats to markdown.",
formatter_class=argparse.RawDescriptionHelpFormatter,
usage=dedent(
"""
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=dedent(
"""\
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 6ea36f9

Please sign in to comment.