@@ -330,11 +330,15 @@ 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 :
333
+ def output (page : str , plain : bool = False ) -> None :
334
334
print ()
335
335
for line in page :
336
336
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 :
338
342
continue
339
343
elif line [0 ] == '#' :
340
344
line = ' ' * LEADING_SPACES_NUM + \
@@ -456,6 +460,11 @@ def create_parser() -> ArgumentParser:
456
460
type = str ,
457
461
help = 'Override the default language' )
458
462
463
+ parser .add_argument ('-m' , '--markdown' ,
464
+ default = False ,
465
+ action = 'store_true' ,
466
+ help = 'Just print the plain page file.' )
467
+
459
468
parser .add_argument (
460
469
'command' , type = str , nargs = '*' , help = "command to lookup" , metavar = 'command'
461
470
).complete = {"bash" : "shtab_tldr_cmd_list" , "zsh" : "shtab_tldr_cmd_list" }
@@ -492,7 +501,7 @@ def main() -> None:
492
501
for command in options .command :
493
502
if os .path .exists (command ):
494
503
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 )
496
505
else :
497
506
try :
498
507
command = '-' .join (options .command )
@@ -509,7 +518,7 @@ def main() -> None:
509
518
" send a pull request to: https://github.com/tldr-pages/tldr"
510
519
).format (cmd = command ))
511
520
else :
512
- output (result )
521
+ output (result , plain = options . markdown )
513
522
except URLError as e :
514
523
sys .exit ("Error fetching from tldr: {}" .format (e ))
515
524
0 commit comments