markdown-link-style

switch between inline and footnote link style in markdown documents.
git clone git://git.ricketyspace.net/markdown-link-style.git
Log | Files | Refs

commit 5dde967f0907460d5bacf5634f6e9ecd955a3f70
parent dd3972a722514d9c49813fe1d05ee24dcf1ecb95
Author: rsiddharth <s@ricketyspace.net>
Date:   Sun,  4 Jun 2017 23:35:49 +0000

mdl_style: Update _get_args.

mdl_style.py (_mdl_stylize): Update function.
(_get_args): Update function.
README.rst: Update file.

Diffstat:
README.rst | 18++++++++++++++----
mdl_style.py | 17+++++++++++++++--
2 files changed, 29 insertions(+), 6 deletions(-)

diff --git 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 @@ -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)