From 5dde967f0907460d5bacf5634f6e9ecd955a3f70 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sun, 4 Jun 2017 23:35:49 +0000 Subject: mdl_style: Update _get_args. mdl_style.py (_mdl_stylize): Update function. (_get_args): Update function. README.rst: Update file. --- README.rst | 18 ++++++++++++++---- mdl_style.py | 17 +++++++++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index e2aa9ec..720f935 100644 --- a/README.rst +++ b/README.rst @@ -20,11 +20,21 @@ usage :: - # switch to footnote link style - $ mdl-style footnote path/to/document.md > document-footnote-style.md + # footnote style - # switch to inline link style - $ mdl-style inline path/to/document.md > document-inline-style.md + ## switch to footnote link style + $ mdl-style footnote path/to/document.md + + ## write footnote link style version to another file + $ mdl-style footnote path/to/document.md path/to/document-footnote-style.md + + # inline style + + ## switch to inline link style + $ mdl-style inline path/to/document.md + + ## write inline link style version to another file + $ mdl-style inline path/to/document.md path/to/document-inline-style.md license ------- diff --git a/mdl_style.py b/mdl_style.py index 46e819d..eb6ed12 100644 --- a/mdl_style.py +++ b/mdl_style.py @@ -249,8 +249,13 @@ def _write_to(file_, content): def _mdl_stylize(args): ls = LinkStyler(args.link_style) - print(ls(args.file), end='') + stylized_content = ls(args.in_file) + if args.out_file: + args.in_file.close() + _write_to(open(args.out_file, 'wt'), stylized_content) + else: + _write_to(args.in_file, stylized_content) def _get_args(args=None): @@ -259,8 +264,16 @@ def _get_args(args=None): version=__version__) parser.add_argument('link_style', choices=['inline', 'footnote'], help='markdown link style.') - parser.add_argument('file', type=argparse.FileType('r'), + parser.add_argument('in_file', type=argparse.FileType('rt+'), help='path to markdown file.') + parser.add_argument('out_file', nargs='?', + type=str, + default=None, + help= ' '.join(['path to output file.', + 'if it is not given, the output is', + 'directly written to the original', + 'in_file.'])) + return parser.parse_args(args) -- cgit v1.2.3