Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Table column width does not properly detect Markdown links #3537

Open
2 tasks done
CollinHeist opened this issue Oct 23, 2024 · 2 comments
Open
2 tasks done

[BUG] Table column width does not properly detect Markdown links #3537

CollinHeist opened this issue Oct 23, 2024 · 2 comments

Comments

@CollinHeist
Copy link

Describe the bug

Markdown links, when rendered in a Table/Column with an auto width (width=None) will improperly resize to fit the "raw" markdown text, not the resulting render. This may result in very wide columns (as URLs are generally very long) when a much shorter result would be sufficient. For example:

image

MRE:

from rich.console import Console
from rich.table import Table
from rich.markdown import Markdown

table = Table(title='Example')
table.add_column('A')
table.add_column('B')

table.add_row('Renders Correctly', 'Short Text')
table.add_row('Renders Incorrectly', Markdown('[Long Text](https://rich.readthedocs.io/en/stable/tables.html)'))

Console().print(table)

Platform

Click to expand
╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface.                                                  │
│                                                                                  │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=134 ColorSystem.TRUECOLOR>                                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                  │
│     color_system = 'truecolor'                                                   │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 72                                                            │
│    is_alt_screen = False                                                         │
│ is_dumb_terminal = False                                                         │
│   is_interactive = True                                                          │
│       is_jupyter = False                                                         │
│      is_terminal = True                                                          │
│   legacy_windows = False                                                         │
│         no_color = False                                                         │
│          options = ConsoleOptions(                                               │
│                        size=ConsoleDimensions(width=134, height=72),             │
│                        legacy_windows=False,                                     │
│                        min_width=1,                                              │
│                        max_width=134,                                            │
│                        is_terminal=True,                                         │
│                        encoding='utf-8',                                         │
│                        max_height=72,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=134, height=72)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 134                                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭── <class 'rich._windows.WindowsConsoleFeatures'> ───╮
│ Windows features available.                         │
│                                                     │
│ ╭─────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=True, truecolor=True) │ │
│ ╰─────────────────────────────────────────────────╯ │
│                                                     │
│ truecolor = True                                    │
│        vt = True                                    │
╰─────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': None,                  │
│     'COLORTERM': None,             │
│     'CLICOLOR': None,              │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': None,          │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Windows"
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@TomJGooding
Copy link
Contributor

TomJGooding commented Oct 24, 2024

Perhaps I'm missing something, but adding Markdown to a Table doesn't have the optimal width regardless if the markdown has a link?

from rich.console import Console
from rich.markdown import Markdown
from rich.table import Table

console = Console()

table = Table()
table.add_column("A")
table.add_column("B")

table.add_row("String", "String")
table.add_row(Markdown("Markdown"), "String")

console.print(table)

If you simply wanted to include hyperlinks in the table, maybe you could simply use console markup as a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants