@@ -330,11 +330,16 @@ def colors_of(key: str) -> Tuple[str, str, List[str]]:
330330 return (color , on_color , attrs )
331331
332332
333- def output (page : str ) -> None :
334- print ()
333+ def output (page : str , plain : bool = False ) -> None :
334+ if not plain :
335+ print ()
335336 for line in page :
336337 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 :
338343 continue
339344 elif line [0 ] == '#' :
340345 line = ' ' * LEADING_SPACES_NUM + \
@@ -456,6 +461,11 @@ def create_parser() -> ArgumentParser:
456461 type = str ,
457462 help = 'Override the default language' )
458463
464+ parser .add_argument ('-m' , '--markdown' ,
465+ default = False ,
466+ action = 'store_true' ,
467+ help = 'Just print the plain page file.' )
468+
459469 parser .add_argument (
460470 'command' , type = str , nargs = '*' , help = "command to lookup" , metavar = 'command'
461471 ).complete = {"bash" : "shtab_tldr_cmd_list" , "zsh" : "shtab_tldr_cmd_list" }
@@ -492,7 +502,8 @@ def main() -> None:
492502 for command in options .command :
493503 if os .path .exists (command ):
494504 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 )
496507 else :
497508 try :
498509 command = '-' .join (options .command )
@@ -509,7 +520,7 @@ def main() -> None:
509520 " send a pull request to: https://github.com/tldr-pages/tldr"
510521 ).format (cmd = command ))
511522 else :
512- output (result )
523+ output (result , plain = options . markdown )
513524 except URLError as e :
514525 sys .exit ("Error fetching from tldr: {}" .format (e ))
515526
0 commit comments