diff options
| -rw-r--r-- | README.rst | 18 | ||||
| -rw-r--r-- | mdl_style.py | 17 | 
2 files changed, 29 insertions, 6 deletions
| @@ -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) | 
