From e79971a7ebaca2f2c75cab3c7ffef7fbc5455153 Mon Sep 17 00:00:00 2001 From: "Daniel J. Perry" <34218082+BioBox@users.noreply.github.com> Date: Sun, 28 Aug 2022 14:53:15 -0400 Subject: [PATCH] Add console entry point (#72) * Add console entry point * Make entry point conform to linter settings. --- markdownify/main.py | 65 +++++++++++++++++++++++++++++++++++++++++++++ setup.py | 5 ++++ 2 files changed, 70 insertions(+) create mode 100644 markdownify/main.py diff --git a/markdownify/main.py b/markdownify/main.py new file mode 100644 index 0000000..87c7c77 --- /dev/null +++ b/markdownify/main.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +import argparse +import sys + +from markdownify import markdownify + + +def main(argv=sys.argv[1:]): + parser = argparse.ArgumentParser( + prog='markdownify', + description='Converts html to markdown.', + ) + + parser.add_argument('html', nargs='?', type=argparse.FileType('r'), + default=sys.stdin, + help="The html file to convert. Defaults to STDIN if not " + "provided.") + parser.add_argument('-s', '--strip', nargs='*', + help="A list of tags to strip. This option can't be used with " + "the --convert option.") + parser.add_argument('-c', '--convert', nargs='*', + help="A list of tags to convert. This option can't be used with " + "the --strip option.") + parser.add_argument('-a', '--autolinks', action='store_true', + help="A boolean indicating whether the 'automatic link' style " + "should be used when a 'a' tag's contents match its href.") + parser.add_argument('--default-title', action='store_false', + help="A boolean to enable setting the title of a link to its " + "href, if no title is given.") + parser.add_argument('--heading-style', + choices=('ATX', 'ATX_CLOSED', 'SETEXT', 'UNDERLINED'), + help="Defines how headings should be converted.") + parser.add_argument('-b', '--bullets', default='*+-', + help="A string of bullet styles to use; the bullet will " + "alternate based on nesting level.") + parser.add_argument('--sub-symbol', default='', + help="Define the chars that surround ''.") + parser.add_argument('--sup-symbol', default='', + help="Define the chars that surround ''.") + parser.add_argument('--code-language', default='', + help="Defines the language that should be assumed for all " + "'
' sections.")
+    parser.add_argument('--no-escape-asterisks', dest='escape_asterisks',
+                        action='store_false',
+                        help="Do not escape '*' to '\\*' in text.")
+    parser.add_argument('--no-escape-underscores', dest='escape_underscores',
+                        action='store_false',
+                        help="Do not escape '_' to '\\_' in text.")
+    parser.add_argument('-i', '--keep-inline-images-in', nargs='*',
+                        help="Images are converted to their alt-text when the images are "
+                        "located inside headlines or table cells. If some inline images "
+                        "should be converted to markdown images instead, this option can "
+                        "be set to a list of parent tags that should be allowed to "
+                        "contain inline images.")
+    parser.add_argument('-w', '--wrap', action='store_true',
+                        help="Wrap all text paragraphs at --wrap-width characters.")
+    parser.add_argument('--wrap-width', type=int, default=80)
+
+    args = parser.parse_args(argv)
+    print(markdownify(**vars(args)))
+
+
+if __name__ == '__main__':
+    main()
diff --git a/setup.py b/setup.py
index dd7c8b1..171c45d 100644
--- a/setup.py
+++ b/setup.py
@@ -96,4 +96,9 @@ setup(
         'test': PyTest,
         'lint': LintCommand,
     },
+    entry_points={
+        'console_scripts': [
+            'markdownify = markdownify.main:main'
+        ]
+    }
 )