|
| 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() |
0 commit comments