diff options
| author | rsiddharth <s@ricketyspace.net> | 2017-06-04 23:35:49 +0000 | 
|---|---|---|
| committer | rsiddharth <s@ricketyspace.net> | 2017-06-04 23:42:45 +0000 | 
| commit | 5dde967f0907460d5bacf5634f6e9ecd955a3f70 (patch) | |
| tree | da6f078e1bd387860701836111ed9e028e3568f8 | |
| parent | dd3972a722514d9c49813fe1d05ee24dcf1ecb95 (diff) | |
mdl_style: Update _get_args.
mdl_style.py (_mdl_stylize): Update function.
(_get_args): Update function.
README.rst: Update file.
| -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) | 
