Skip to content

Commit 1f314c1

Browse files
Merge pull request #609 from Crozzers/add-output-to-file
Add option to output to file in CLI (#608)
2 parents 1d37310 + 2267c43 commit 1f314c1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- [pull #605] Add support for Python 3.13, drop EOL 3.8
66
- [pull #607] Fix `middle-word-em` extra preventing strongs from being recognized (#606)
7+
- [pull #609] Add option to output to file in CLI (#608)
78

89

910
## python-markdown2 2.5.1

lib/markdown2.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3985,6 +3985,7 @@ def main(argv=None):
39853985
help="run internal self-tests (some doctests)")
39863986
parser.add_argument("--compare", action="store_true",
39873987
help="run against Markdown.pl as well (for testing)")
3988+
parser.add_argument('--output', type=str, help='output to a file instead of stdout')
39883989
parser.set_defaults(log_level=logging.INFO, compare=False,
39893990
encoding="utf-8", safe_mode=None, use_file_vars=False)
39903991
opts = parser.parse_args()
@@ -4059,7 +4060,11 @@ def main(argv=None):
40594060
extras=extras, link_patterns=link_patterns,
40604061
use_file_vars=opts.use_file_vars,
40614062
cli=True)
4062-
sys.stdout.write(html)
4063+
if opts.output:
4064+
with open(opts.output, 'w') as f:
4065+
f.write(html)
4066+
else:
4067+
sys.stdout.write(html)
40634068
if extras and "toc" in extras:
40644069
log.debug("toc_html: " +
40654070
str(html.toc_html.encode(sys.stdout.encoding or "utf-8", 'xmlcharrefreplace')))

0 commit comments

Comments
 (0)