@@ -330,11 +330,16 @@ def colors_of(key: str) -> Tuple[str, str, List[str]]:
330
330
return (color , on_color , attrs )
331
331
332
332
333
- def output (page : str ) -> None :
334
- print ()
333
+ def output (page : str , plain : bool = False ) -> None :
334
+ if not plain :
335
+ print ()
335
336
for line in page :
336
337
line = line .rstrip ().decode ('utf-8' )
337
- if len (line ) == 0 :
338
+
339
+ if plain :
340
+ print (line )
341
+ continue
342
+ elif len (line ) == 0 :
338
343
continue
339
344
elif line [0 ] == '#' :
340
345
line = ' ' * LEADING_SPACES_NUM + \
@@ -456,6 +461,11 @@ def create_parser() -> ArgumentParser:
456
461
type = str ,
457
462
help = 'Override the default language' )
458
463
464
+ parser .add_argument ('-m' , '--markdown' ,
465
+ default = False ,
466
+ action = 'store_true' ,
467
+ help = 'Just print the plain page file.' )
468
+
459
469
parser .add_argument (
460
470
'command' , type = str , nargs = '*' , help = "command to lookup" , metavar = 'command'
461
471
).complete = {"bash" : "shtab_tldr_cmd_list" , "zsh" : "shtab_tldr_cmd_list" }
@@ -492,7 +502,8 @@ def main() -> None:
492
502
for command in options .command :
493
503
if os .path .exists (command ):
494
504
with open (command , encoding = 'utf-8' ) as open_file :
495
- output (open_file .read ().encode ('utf-8' ).splitlines ())
505
+ output (open_file .read ().encode ('utf-8' ).splitlines (),
506
+ plain = options .markdown )
496
507
else :
497
508
try :
498
509
command = '-' .join (options .command )
@@ -509,7 +520,7 @@ def main() -> None:
509
520
" send a pull request to: https://github.com/tldr-pages/tldr"
510
521
).format (cmd = command ))
511
522
else :
512
- output (result )
523
+ output (result , plain = options . markdown )
513
524
except URLError as e :
514
525
sys .exit ("Error fetching from tldr: {}" .format (e ))
515
526
0 commit comments