Skip to content

Commit 0867638

Browse files
committed
add the option to simply print the md file
1 parent de6c3d2 commit 0867638

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tldr.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,15 @@ def colors_of(key: str) -> Tuple[str, str, List[str]]:
330330
return (color, on_color, attrs)
331331

332332

333-
def output(page: str) -> None:
333+
def output(page: str, plain: bool = False) -> None:
334334
print()
335335
for line in page:
336336
line = line.rstrip().decode('utf-8')
337-
if len(line) == 0:
337+
338+
if plain:
339+
print(line)
340+
continue
341+
elif len(line) == 0:
338342
continue
339343
elif line[0] == '#':
340344
line = ' ' * LEADING_SPACES_NUM + \
@@ -456,6 +460,11 @@ def create_parser() -> ArgumentParser:
456460
type=str,
457461
help='Override the default language')
458462

463+
parser.add_argument('-m', '--markdown',
464+
default=False,
465+
action='store_true',
466+
help='Just print the plain page file.')
467+
459468
parser.add_argument(
460469
'command', type=str, nargs='*', help="command to lookup", metavar='command'
461470
).complete = {"bash": "shtab_tldr_cmd_list", "zsh": "shtab_tldr_cmd_list"}
@@ -492,7 +501,7 @@ def main() -> None:
492501
for command in options.command:
493502
if os.path.exists(command):
494503
with open(command, encoding='utf-8') as open_file:
495-
output(open_file.read().encode('utf-8').splitlines())
504+
output(open_file.read().encode('utf-8').splitlines(), plain=options.markdown)
496505
else:
497506
try:
498507
command = '-'.join(options.command)
@@ -509,7 +518,7 @@ def main() -> None:
509518
" send a pull request to: https://github.com/tldr-pages/tldr"
510519
).format(cmd=command))
511520
else:
512-
output(result)
521+
output(result, plain=options.markdown)
513522
except URLError as e:
514523
sys.exit("Error fetching from tldr: {}".format(e))
515524

0 commit comments

Comments
 (0)