Skip to content

Potential bug with new lines in the help output when markdown mode is used #447

@renardeinside

Description

@renardeinside

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

import typer

app = typer.Typer(rich_markup_mode="markdown", name="tester-app")

@app.command(name="tester-cmd", help="""
    Header

    Line 1
    Line 2
    Line 3
""")
def cmd():
    pass

if __name__ == "__main__":
    app()

Description

  • Create the typer application as above
  • Run this application with --help switch
  • Lines are not properly formatted (they don't start from a newline):

Input:

> tester-app tester-cmd --help

Output:

 Usage: dbx tester-cmd [OPTIONS]                                                                                                                                            
                                                                                                                                                                            
Header                                                                                                                                                                     
Line 1 Line 2 Line 3     

Expected output:

Header                                                                                                                                                                     
Line 1 
Line 2
Line 3     

If I run the same command with: app = typer.Typer(rich_markup_mode="rich", name="tester-app")

I get the expected result:

 Header                                                                                                                                                                     
 Line 1                                                                                                                                                                     
 Line 2                                                                                                                                                                     
 Line 3   

If I add more newlines in markdown mode, I get the following:
Input:

@app.command(name="tester-cmd", help="""
    Header

    Line 1

    Line 2

    Line 3
""")
def cmd():
    pass        

Output:

 Header                                                                                                                                                                     
 Line 1 Line 2 Line 3 

It only works if I add 3 newlines:
Input:

@app.command(name="tester-cmd", help="""
    Header

    Line 1



    Line 2



    Line 3
""")
def cmd():
    pass

Output:

 Header                                                                                                                                                                     
 Line 1                                                                                                                                                                     
                                                                                                                                                                            
 Line 2                                                                                                                                                                     
                                                                                                                                                                            
 Line 3 

But it's also not the desired output. Desired output would be something similar to rich formatting:

 Header                                                                                                                                                                     
 Line 1                                                                                                                                                                     
 Line 2                                                                                                                                                                     
 Line 3   

Operating System

macOS

Operating System Details

Apple M1, macOs Monterey 12.2.1

Typer Version

0.6.1

Python Version

Python 3.9.12

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions