Skip to content

Commit e79971a

Browse files
authored
Add console entry point (#72)
* Add console entry point * Make entry point conform to linter settings.
1 parent 5adda13 commit e79971a

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

markdownify/main.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import sys
5+
6+
from markdownify import markdownify
7+
8+
9+
def main(argv=sys.argv[1:]):
10+
parser = argparse.ArgumentParser(
11+
prog='markdownify',
12+
description='Converts html to markdown.',
13+
)
14+
15+
parser.add_argument('html', nargs='?', type=argparse.FileType('r'),
16+
default=sys.stdin,
17+
help="The html file to convert. Defaults to STDIN if not "
18+
"provided.")
19+
parser.add_argument('-s', '--strip', nargs='*',
20+
help="A list of tags to strip. This option can't be used with "
21+
"the --convert option.")
22+
parser.add_argument('-c', '--convert', nargs='*',
23+
help="A list of tags to convert. This option can't be used with "
24+
"the --strip option.")
25+
parser.add_argument('-a', '--autolinks', action='store_true',
26+
help="A boolean indicating whether the 'automatic link' style "
27+
"should be used when a 'a' tag's contents match its href.")
28+
parser.add_argument('--default-title', action='store_false',
29+
help="A boolean to enable setting the title of a link to its "
30+
"href, if no title is given.")
31+
parser.add_argument('--heading-style',
32+
choices=('ATX', 'ATX_CLOSED', 'SETEXT', 'UNDERLINED'),
33+
help="Defines how headings should be converted.")
34+
parser.add_argument('-b', '--bullets', default='*+-',
35+
help="A string of bullet styles to use; the bullet will "
36+
"alternate based on nesting level.")
37+
parser.add_argument('--sub-symbol', default='',
38+
help="Define the chars that surround '<sub>'.")
39+
parser.add_argument('--sup-symbol', default='',
40+
help="Define the chars that surround '<sup>'.")
41+
parser.add_argument('--code-language', default='',
42+
help="Defines the language that should be assumed for all "
43+
"'<pre>' sections.")
44+
parser.add_argument('--no-escape-asterisks', dest='escape_asterisks',
45+
action='store_false',
46+
help="Do not escape '*' to '\\*' in text.")
47+
parser.add_argument('--no-escape-underscores', dest='escape_underscores',
48+
action='store_false',
49+
help="Do not escape '_' to '\\_' in text.")
50+
parser.add_argument('-i', '--keep-inline-images-in', nargs='*',
51+
help="Images are converted to their alt-text when the images are "
52+
"located inside headlines or table cells. If some inline images "
53+
"should be converted to markdown images instead, this option can "
54+
"be set to a list of parent tags that should be allowed to "
55+
"contain inline images.")
56+
parser.add_argument('-w', '--wrap', action='store_true',
57+
help="Wrap all text paragraphs at --wrap-width characters.")
58+
parser.add_argument('--wrap-width', type=int, default=80)
59+
60+
args = parser.parse_args(argv)
61+
print(markdownify(**vars(args)))
62+
63+
64+
if __name__ == '__main__':
65+
main()

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,9 @@ def run(self):
9696
'test': PyTest,
9797
'lint': LintCommand,
9898
},
99+
entry_points={
100+
'console_scripts': [
101+
'markdownify = markdownify.main:main'
102+
]
103+
}
99104
)

0 commit comments

Comments
 (0)