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

rich.markdown generates AssertionError rendering certain strings #3053

Closed
2 tasks done
jspv opened this issue Jul 25, 2023 · 2 comments · Fixed by #3064
Closed
2 tasks done

rich.markdown generates AssertionError rendering certain strings #3053

jspv opened this issue Jul 25, 2023 · 2 comments · Fixed by #3064

Comments

@jspv
Copy link

jspv commented Jul 25, 2023

Moved from here

The following string "| Simple | Table |\n| ------ | -----" or similar ones that are incomplete tables will generate AssertionError rather than printing the string.

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

# This will work
responses = "| Simple | Table |\n| ------ | ----- |\n| cell1  | cell2 |"

# This will not work
responses = "| Simple | Table |\n| ------ | ----- "

console = Console()
md = Markdown(responses)
console.print(md)

Results:

Traceback (most recent call last):
  File "/Users/justin/src/mchat/rtest.py", line 12, in <module>
    console.print(md)
  File "/Users/justin/Library/Caches/pypoetry/virtualenvs/mchat-mvZqEniY-py3.11/lib/python3.11/site-packages/rich/console.py", line 1699, in print
    extend(render(renderable, render_options))
  File "/Users/justin/Library/Caches/pypoetry/virtualenvs/mchat-mvZqEniY-py3.11/lib/python3.11/site-packages/rich/console.py", line 1331, in render
    for render_output in iter_render:
  File "/Users/justin/Library/Caches/pypoetry/virtualenvs/mchat-mvZqEniY-py3.11/lib/python3.11/site-packages/rich/markdown.py", line 686, in __rich_console__
    yield from console.render(element, context.options)
  File "/Users/justin/Library/Caches/pypoetry/virtualenvs/mchat-mvZqEniY-py3.11/lib/python3.11/site-packages/rich/console.py", line 1331, in render
    for render_output in iter_render:
  File "/Users/justin/Library/Caches/pypoetry/virtualenvs/mchat-mvZqEniY-py3.11/lib/python3.11/site-packages/rich/markdown.py", line 262, in __rich_console__
    assert self.body is not None
           ^^^^^^^^^^^^^^^^^^^^^
AssertionError

Platform

Click to expand

MacOS 13.4.1

╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface.                                                  │
│                                                                                  │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=187 ColorSystem.TRUECOLOR>                                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                  │
│     color_system = 'truecolor'                                                   │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 50                                                            │
│    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=187, height=50),             │
│                        legacy_windows=False,                                     │
│                        min_width=1,                                              │
│                        max_width=187,                                            │
│                        is_terminal=True,                                         │
│                        encoding='utf-8',                                         │
│                        max_height=50,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=187, height=50)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 187                                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'xterm-256color',      │
│     'COLORTERM': 'truecolor',      │
│     'CLICOLOR': None,              │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': 'iTerm.app',   │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Darwin"
rich==13.4.2
@github-actions
Copy link

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@github-actions
Copy link

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

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

Successfully merging a pull request may close this issue.

1 participant